Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Services > how to consume entity object from web service

Reply
Thread Tools

how to consume entity object from web service

 
 
Antonio (MCAD)
Guest
Posts: n/a
 
      06-25-2007
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
 
 
 
 
John Saunders [MVP]
Guest
Posts: n/a
 
      06-25-2007
"Antonio (MCAD)" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
 
 
 
 
Antonio (MCAD)
Guest
Posts: n/a
 
      06-25-2007


"John Saunders [MVP]" wrote:

> "Antonio (MCAD)" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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
 
Antonio (MCAD)
Guest
Posts: n/a
 
      06-25-2007
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:

> "Antonio (MCAD)" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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
 
John Saunders [MVP]
Guest
Posts: n/a
 
      06-26-2007
"Antonio (MCAD)" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> 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
 
Antonio (MCAD)
Guest
Posts: n/a
 
      06-26-2007
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)" <(E-Mail Removed)> wrote in message
> news(E-Mail Removed)...
> > 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
 
John Saunders [MVP]
Guest
Posts: n/a
 
      06-26-2007
"Antonio (MCAD)" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
 
Antonio (MCAD)
Guest
Posts: n/a
 
      06-26-2007
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:

> 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)" <(E-Mail Removed)> wrote in message
> > news(E-Mail Removed)...
> > > 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

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
consume local web service -ok consume remote service - Not OK dgleeson422111 ASP .Net Web Services 2 01-31-2010 08:02 PM
How to relate a SQL based entity with an Object based entity in Entity Framework markla ASP .Net 1 10-06-2008 09:42 AM
problem trying to consume web service that returns a strongly typeddataset from 1.1 web app steven ASP .Net 0 08-21-2008 02:40 PM
Entity Name or Entity Number? Samuel van Laere HTML 4 02-24-2007 10:11 PM



Advertisments