how to consume entity object from web service

Discussion in 'ASP .Net Web Services' started by Antonio (MCAD), Jun 25, 2007.

  1. 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.
    Antonio (MCAD), Jun 25, 2007
    #1
    1. Advertising

  2. "Antonio (MCAD)" <> wrote in message
    news:...
    > 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]
    John Saunders [MVP], Jun 25, 2007
    #2
    1. Advertising

  3. "John Saunders [MVP]" wrote:

    > "Antonio (MCAD)" <> wrote in message
    > news:...
    > > 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]
    >
    >
    Antonio (MCAD), Jun 25, 2007
    #3
  4. 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)" <> wrote in message
    > news:...
    > > 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]
    >
    >
    Antonio (MCAD), Jun 25, 2007
    #4
  5. "Antonio (MCAD)" <> wrote in message
    news:D...
    > 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/library/system.data.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]
    John Saunders [MVP], Jun 26, 2007
    #5
  6. 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).Quantity > 0)
    {
    //TODO: Add link to OrderStatus.Status field
    }
    }
    }



    "John Saunders [MVP]" wrote:

    > "Antonio (MCAD)" <> wrote in message
    > news:D...
    > > 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/library/system.data.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]
    >
    >
    Antonio (MCAD), Jun 26, 2007
    #6
  7. "Antonio (MCAD)" <> wrote in message
    news:...
    > 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]
    John Saunders [MVP], Jun 26, 2007
    #7
  8. 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).Quantity > 0)
    > {
    > //TODO: Add link to OrderStatus.Status field
    > }
    > }
    > }
    >
    >
    >
    > "John Saunders [MVP]" wrote:
    >
    > > "Antonio (MCAD)" <> wrote in message
    > > news:D...
    > > > 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/library/system.data.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]
    > >
    > >
    Antonio (MCAD), Jun 26, 2007
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. msnews.microsoft.com
    Replies:
    2
    Views:
    1,157
    =?Utf-8?B?R2FyeQ==?=
    May 19, 2004
  2. Jorge Luzarraga Castro

    Is it possible to consume a Web Service from an ASP Client?

    Jorge Luzarraga Castro, Nov 3, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    404
    S.M. Altaf [MVP]
    Nov 3, 2005
  3. steven
    Replies:
    0
    Views:
    312
    steven
    Aug 21, 2008
  4. markla
    Replies:
    1
    Views:
    545
    Steven Cheng
    Oct 6, 2008
  5. dgleeson422111

    consume local web service -ok consume remote service - Not OK

    dgleeson422111, Jan 26, 2010, in forum: ASP .Net Web Services
    Replies:
    2
    Views:
    1,605
    dgleeson422111
    Jan 31, 2010
Loading...

Share This Page