HighTechTalks DotNet Forums  

how to consume entity object from web service

ASP.net Web Services microsoft.public.dotnet.framework.aspnet.webservices


Discuss how to consume entity object from web service in the ASP.net Web Services forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
=?Utf-8?B?QW50b25pbyAoTUNBRCk=?=
 
Posts: n/a

Default how to consume entity object from web service - 06-25-2007 , 03:06 PM






My question is I have [WebMethod] that returns an array of a object of Type
OrderStatus[]. I am not using datasets, but I want to consume this from the
web application and populate a repeater control. I want to be able to take
this data and filter out certain rows before binding to the repeater. I just
need some example code on the .net 2 web application side to see how to take
this data and modify it:

This is what I have today:

Presentation Code:
WebService src = new WebService ();
Repeater1.DataSource = src.GetOrderStatusSummary();
Repeater1.DataBind();

Application Code:
[WebMethod]
public OrderStatus[] GetOrderStatusSummary()
{
return OrderManager.GetOrderStatusSummary();
}


Thank You.


Reply With Quote
  #2  
Old   
John Saunders [MVP]
 
Posts: n/a

Default Re: how to consume entity object from web service - 06-25-2007 , 05:38 PM






"Antonio (MCAD)" <AntonioMCAD (AT) discussions (DOT) microsoft.com> wrote

Quote:
My question is I have [WebMethod] that returns an array of a object of
Type
OrderStatus[]. I am not using datasets, but I want to consume this from
the
web application and populate a repeater control. I want to be able to
take
this data and filter out certain rows before binding to the repeater. I
just
need some example code on the .net 2 web application side to see how to
take
this data and modify it:

This is what I have today:

Presentation Code:
WebService src = new WebService ();
Repeater1.DataSource = src.GetOrderStatusSummary();
Repeater1.DataBind();
You can do this in one of several ways. Here's a simple way:

using (WebService src = new WebService()) // Remember that they implement
IDisposable
{
List<OrderStatus> rawList = new
List<OrderStatus>(src.GetOrderStatusSummary());
List<OrderStatus> filteredList = rawList.FindAll(
delegate(OrderStatus os)
{
if (os.Field1 > 100 && // Your criteria here
os.Field2 == "something")
{
return true;
}
else
{
return false;
}
});
Repeater1.DataSource = filteredList;
Repeater1.DataBind();
}
--
John Saunders [MVP]



Reply With Quote
  #3  
Old   
=?Utf-8?B?QW50b25pbyAoTUNBRCk=?=
 
Posts: n/a

Default Re: how to consume entity object from web service - 06-25-2007 , 06:08 PM





"John Saunders [MVP]" wrote:

Quote:
"Antonio (MCAD)" <AntonioMCAD (AT) discussions (DOT) microsoft.com> wrote in message
news:58E19B42-CDA5-40C5-BA91-48670CE95608 (AT) microsoft (DOT) com...
My question is I have [WebMethod] that returns an array of a object of
Type
OrderStatus[]. I am not using datasets, but I want to consume this from
the
web application and populate a repeater control. I want to be able to
take
this data and filter out certain rows before binding to the repeater. I
just
need some example code on the .net 2 web application side to see how to
take
this data and modify it:

This is what I have today:

Presentation Code:
WebService src = new WebService ();
Repeater1.DataSource = src.GetOrderStatusSummary();
Repeater1.DataBind();

You can do this in one of several ways. Here's a simple way:

using (WebService src = new WebService()) // Remember that they implement
IDisposable
{
List<OrderStatus> rawList = new
List<OrderStatus>(src.GetOrderStatusSummary());
List<OrderStatus> filteredList = rawList.FindAll(
delegate(OrderStatus os)
{
if (os.Field1 > 100 && // Your criteria here
os.Field2 == "something")
{
return true;
}
else
{
return false;
}
});
Repeater1.DataSource = filteredList;
Repeater1.DataBind();
}
--
John Saunders [MVP]



Reply With Quote
  #4  
Old   
=?Utf-8?B?QW50b25pbyAoTUNBRCk=?=
 
Posts: n/a

Default Re: how to consume entity object from web service - 06-25-2007 , 06:28 PM



John,

That worked perfectly! I have been trying to find examples of this on
google with no luck. You mentioned there are several ways of doing this, do
you have any links that I can read up on to learn about this area?

thanks Again!

"John Saunders [MVP]" wrote:

Quote:
"Antonio (MCAD)" <AntonioMCAD (AT) discussions (DOT) microsoft.com> wrote in message
news:58E19B42-CDA5-40C5-BA91-48670CE95608 (AT) microsoft (DOT) com...
My question is I have [WebMethod] that returns an array of a object of
Type
OrderStatus[]. I am not using datasets, but I want to consume this from
the
web application and populate a repeater control. I want to be able to
take
this data and filter out certain rows before binding to the repeater. I
just
need some example code on the .net 2 web application side to see how to
take
this data and modify it:

This is what I have today:

Presentation Code:
WebService src = new WebService ();
Repeater1.DataSource = src.GetOrderStatusSummary();
Repeater1.DataBind();

You can do this in one of several ways. Here's a simple way:

using (WebService src = new WebService()) // Remember that they implement
IDisposable
{
List<OrderStatus> rawList = new
List<OrderStatus>(src.GetOrderStatusSummary());
List<OrderStatus> filteredList = rawList.FindAll(
delegate(OrderStatus os)
{
if (os.Field1 > 100 && // Your criteria here
os.Field2 == "something")
{
return true;
}
else
{
return false;
}
});
Repeater1.DataSource = filteredList;
Repeater1.DataBind();
}
--
John Saunders [MVP]



Reply With Quote
  #5  
Old   
John Saunders [MVP]
 
Posts: n/a

Default Re: how to consume entity object from web service - 06-26-2007 , 11:46 AM



"Antonio (MCAD)" <AntonioMCAD (AT) discussions (DOT) microsoft.com> wrote

Quote:
John,

That worked perfectly! I have been trying to find examples of this on
google with no luck. You mentioned there are several ways of doing this,
do
you have any links that I can read up on to learn about this area?
Antonio, I'm glad that helped.

I don't really have further links. I'd look at the features of the DataView
class (http://msdn2.microsoft.com/en-us/lib...dataview.aspx).
You can load your web service data into a DataSet (I do not recommend that
your web service _return_ a DataSet) and then use a DataView to sort and
filter it. You can then bind to the DataView. This is very flexible.

You can go further than this if necessary, and create a DataSet with
multiple, related tables. Some can come from your web service, some from a
database, some from one or more files. You can create columns in the DataSet
that are calculated from other columns, or even calculated by running totals
across multiple rows. This can get as fancy as you like.

The basic rule I'd use is to keep the web service interface fairly simple,
using arrays instead of ArrayLists or generic lists. Then, load it into
something more convenient on the client side and go wild!
--
John Saunders [MVP]



Reply With Quote
  #6  
Old   
=?Utf-8?B?QW50b25pbyAoTUNBRCk=?=
 
Posts: n/a

Default Re: how to consume entity object from web service - 06-26-2007 , 12:52 PM



John,

You have been greatful in providing this information. Now i have another
question which leads from the first question.

My webmethod returned the object and with your help i was able to filter the
list and bind it to the appropiate repeater control with no problems. Now i
would like to use the rp1_ItemDataBound event to modify a field of data based
on the results of the other field. So my object from previous example
returns a status field and a quantity field. I want to provide a link to the
status field if the quantity is greater than zero.

I can not figure out how to resolve the field
(WebService.OrderStatus)e.Item.DataItem).Quantity below???

This is what I have:

protected void Repeater1_ItemDataBound(Object sender,
RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item)
{
if (((WebService.OrderStatus)e.Item.DataItem).Quantit y > 0)
{
//TODO: Add link to OrderStatus.Status field
}
}
}



"John Saunders [MVP]" wrote:

Quote:
"Antonio (MCAD)" <AntonioMCAD (AT) discussions (DOT) microsoft.com> wrote in message
newsD8994A4-F5F1-49F4-9E1F-665BE39E208B (AT) microsoft (DOT) com...
John,

That worked perfectly! I have been trying to find examples of this on
google with no luck. You mentioned there are several ways of doing this,
do
you have any links that I can read up on to learn about this area?

Antonio, I'm glad that helped.

I don't really have further links. I'd look at the features of the DataView
class (http://msdn2.microsoft.com/en-us/lib...dataview.aspx).
You can load your web service data into a DataSet (I do not recommend that
your web service _return_ a DataSet) and then use a DataView to sort and
filter it. You can then bind to the DataView. This is very flexible.

You can go further than this if necessary, and create a DataSet with
multiple, related tables. Some can come from your web service, some from a
database, some from one or more files. You can create columns in the DataSet
that are calculated from other columns, or even calculated by running totals
across multiple rows. This can get as fancy as you like.

The basic rule I'd use is to keep the web service interface fairly simple,
using arrays instead of ArrayLists or generic lists. Then, load it into
something more convenient on the client side and go wild!
--
John Saunders [MVP]



Reply With Quote
  #7  
Old   
John Saunders [MVP]
 
Posts: n/a

Default Re: how to consume entity object from web service - 06-26-2007 , 01:24 PM



"Antonio (MCAD)" <AntonioMCAD (AT) discussions (DOT) microsoft.com> wrote

Quote:
John,

You have been greatful in providing this information. Now i have another
question which leads from the first question.

My webmethod returned the object and with your help i was able to filter
the
list and bind it to the appropiate repeater control with no problems. Now
i
would like to use the rp1_ItemDataBound event to modify a field of data
based
on the results of the other field. So my object from previous example
returns a status field and a quantity field. I want to provide a link to
the
status field if the quantity is greater than zero.

I can not figure out how to resolve the field
(WebService.OrderStatus)e.Item.DataItem).Quantity below???
I'm not sure from your post which problem you're having. Is it that you
can't access the Quantity field, or that you can't add the link? Also, I'm
not sure what you mean when you say "add a link to the status field".

--
John Saunders [MVP]



Reply With Quote
  #8  
Old   
=?Utf-8?B?QW50b25pbyAoTUNBRCk=?=
 
Posts: n/a

Default Re: how to consume entity object from web service - 06-26-2007 , 01:30 PM



I have figured out my own problem and I am posting it here:

protected void Repeater1_ItemDataBound(Object sender,
RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
if (((OrderStatus)e.Item.DataItem).Qty != "0")
{
//TODO: add the hyperlink
}
}
}



"Antonio (MCAD)" wrote:

Quote:
John,

You have been greatful in providing this information. Now i have another
question which leads from the first question.

My webmethod returned the object and with your help i was able to filter the
list and bind it to the appropiate repeater control with no problems. Now i
would like to use the rp1_ItemDataBound event to modify a field of data based
on the results of the other field. So my object from previous example
returns a status field and a quantity field. I want to provide a link to the
status field if the quantity is greater than zero.

I can not figure out how to resolve the field
(WebService.OrderStatus)e.Item.DataItem).Quantity below???

This is what I have:

protected void Repeater1_ItemDataBound(Object sender,
RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item)
{
if (((WebService.OrderStatus)e.Item.DataItem).Quantit y > 0)
{
//TODO: Add link to OrderStatus.Status field
}
}
}



"John Saunders [MVP]" wrote:

"Antonio (MCAD)" <AntonioMCAD (AT) discussions (DOT) microsoft.com> wrote in message
newsD8994A4-F5F1-49F4-9E1F-665BE39E208B (AT) microsoft (DOT) com...
John,

That worked perfectly! I have been trying to find examples of this on
google with no luck. You mentioned there are several ways of doing this,
do
you have any links that I can read up on to learn about this area?

Antonio, I'm glad that helped.

I don't really have further links. I'd look at the features of the DataView
class (http://msdn2.microsoft.com/en-us/lib...dataview.aspx).
You can load your web service data into a DataSet (I do not recommend that
your web service _return_ a DataSet) and then use a DataView to sort and
filter it. You can then bind to the DataView. This is very flexible.

You can go further than this if necessary, and create a DataSet with
multiple, related tables. Some can come from your web service, some from a
database, some from one or more files. You can create columns in the DataSet
that are calculated from other columns, or even calculated by running totals
across multiple rows. This can get as fancy as you like.

The basic rule I'd use is to keep the web service interface fairly simple,
using arrays instead of ArrayLists or generic lists. Then, load it into
something more convenient on the client side and go wild!
--
John Saunders [MVP]



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.