Nested objects?

Discussion in 'ASP .Net Web Services' started by Arjen, Oct 18, 2005.

  1. Arjen

    Arjen Guest

    Hi,

    I want to make a webservice that returns an order with orderlines.
    How can this be best done?

    Can this be done with an object order (class order) that haves a property
    arraylist of orderline objects (class orderline)?

    Hope someone can help, thanks!
    Arjen, Oct 18, 2005
    #1
    1. Advertising

  2. It depends of what you have (or could have) on the other side... I mean, all
    the app.consumers are .NET based or thay could be from any other platform
    like Java?
    ------------
    A.- METHOD ONE.
    If you have .NET on both end-points (WS and cosumer) you can use DataSets
    (because DataSets are automatically serialized to XML), within that DataSet,
    one DataTable could be for the main Order and another DataTable could be for
    Order details. This is the easiest way to do it with .NET.
    To do so, just return a DataSet as a return function value from your
    WebMethod and get it from the consumer App. It is straight forward and
    extremely easy.
    BUT, using DataSets have several handicaps:
    1.- You'll have interoperability problem if you want to consume your
    WebService from any other platform like Java, because of DataSet's Schema
    issues. Take into account that .NET DataSets (like Vectors in Java) are
    platform specific types that can't be represented easily in other platforms.
    This is because there is currently no single well-defined mapping between
    such platform-specific types and XML. Just because a .NET client can
    recognize a blob of XML as a Dataset, it doesn't mean a Web service client
    written in Java can do the same. Interoperability problems arise as a result.
    2.- Depending of your bandwidth, DataSets are a bit heavy (big XML
    structures).
    ----------
    B.- METHOD TWO.
    The other way is to use plain Clasess and structures, and define first your
    WSDL (it is called "Contract First"), and serializing those clasess using
    Attributes, etc. This way, you'll have to work a little bit more (more
    programming) but because you are defining "The Contract First" (WSDL), it
    will be interoperable with any other platform like Java. It also will have
    more performance because SOAP messages will likely have a lighter schema and
    XML.
    To use plain classes ans serializing by your self, take a look to this URL:
    - Exposing custom-made classes through a Webservice and binding them to a
    DataGrid
    http://www.codeproject.com/vb/net/leaditwebservicewrapper.asp
    This is a really nice article.
    And:
    - Contract First Web Services Interoperability between Microsoft .NET and
    IBM WebSphere:
    http://msdn.microsoft.com/vstudio/java/interop/websphereinterop/default.aspx

    BTW, about your question (using ArrayLists), here you have an example. BUT
    using ArrayLists IS NOT INTEROPERABLE either. If all you have is .NET, great.
    But if you have Java on the other point..., you'll have problems:

    namespace Orders
    {
    [WebService(Namespace="http://services.orders")]
    public class OrdersService: WebService
    {

    public struct Product {
    public string name;
    public int qty;
    public float price;
    }

    [WebMethod]
    [XmlInclude(typeof(Product))]
    public ArrayList updateOrderProducts(ArrayList products)
    {
    ArrayList newList = new ArrayList();
    IEnumerator eList = products.GetEnumerator();
    while(eList.MoveNext())
    {
    Product item = (Product)(eList.Current);
    // DO whatever, f.i. updating each product...
    newList.Add(item);
    }
    //Return Updated Products
    return newList;
    }
    }
    } (I have not tested this sample, just wrote it like it can be)

    So, it depends of your scenario.
    Of course, if all you have is .NET and you are starting with WebServices,
    DataSets and ArrayLists are really easy.

    --
    CESAR DE LA TORRE
    Software Architect
    [Microsoft MVP - XML Web Services]
    [MCSE] [MCT]

    Renacimiento
    [Microsoft GOLD Certified Partner]


    "Arjen" wrote:

    > Hi,
    >
    > I want to make a webservice that returns an order with orderlines.
    > How can this be best done?
    >
    > Can this be done with an object order (class order) that haves a property
    > arraylist of orderline objects (class orderline)?
    >
    > Hope someone can help, thanks!
    >
    >
    >
    CESAR DE LA TORRE [MVP], Oct 18, 2005
    #2
    1. Advertising

  3. Arjen

    Arjen Guest

    Okay, thanks!

    Maybe I will use method 3... split up orders and orderlines.

    What happens when I want to return multiple orders or orderlines?
    Do I get the same problem (array?)?

    Thanks!



    "CESAR DE LA TORRE [MVP]" <> schreef in bericht
    news:...
    > It depends of what you have (or could have) on the other side... I mean,
    > all
    > the app.consumers are .NET based or thay could be from any other platform
    > like Java?
    > ------------
    > A.- METHOD ONE.
    > If you have .NET on both end-points (WS and cosumer) you can use DataSets
    > (because DataSets are automatically serialized to XML), within that
    > DataSet,
    > one DataTable could be for the main Order and another DataTable could be
    > for
    > Order details. This is the easiest way to do it with .NET.
    > To do so, just return a DataSet as a return function value from your
    > WebMethod and get it from the consumer App. It is straight forward and
    > extremely easy.
    > BUT, using DataSets have several handicaps:
    > 1.- You'll have interoperability problem if you want to consume your
    > WebService from any other platform like Java, because of DataSet's Schema
    > issues. Take into account that .NET DataSets (like Vectors in Java) are
    > platform specific types that can't be represented easily in other
    > platforms.
    > This is because there is currently no single well-defined mapping between
    > such platform-specific types and XML. Just because a .NET client can
    > recognize a blob of XML as a Dataset, it doesn't mean a Web service client
    > written in Java can do the same. Interoperability problems arise as a
    > result.
    > 2.- Depending of your bandwidth, DataSets are a bit heavy (big XML
    > structures).
    > ----------
    > B.- METHOD TWO.
    > The other way is to use plain Clasess and structures, and define first
    > your
    > WSDL (it is called "Contract First"), and serializing those clasess using
    > Attributes, etc. This way, you'll have to work a little bit more (more
    > programming) but because you are defining "The Contract First" (WSDL), it
    > will be interoperable with any other platform like Java. It also will have
    > more performance because SOAP messages will likely have a lighter schema
    > and
    > XML.
    > To use plain classes ans serializing by your self, take a look to this
    > URL:
    > - Exposing custom-made classes through a Webservice and binding them to a
    > DataGrid
    > http://www.codeproject.com/vb/net/leaditwebservicewrapper.asp
    > This is a really nice article.
    > And:
    > - Contract First Web Services Interoperability between Microsoft .NET and
    > IBM WebSphere:
    > http://msdn.microsoft.com/vstudio/java/interop/websphereinterop/default.aspx
    >
    > BTW, about your question (using ArrayLists), here you have an example. BUT
    > using ArrayLists IS NOT INTEROPERABLE either. If all you have is .NET,
    > great.
    > But if you have Java on the other point..., you'll have problems:
    >
    > namespace Orders
    > {
    > [WebService(Namespace="http://services.orders")]
    > public class OrdersService: WebService
    > {
    >
    > public struct Product {
    > public string name;
    > public int qty;
    > public float price;
    > }
    >
    > [WebMethod]
    > [XmlInclude(typeof(Product))]
    > public ArrayList updateOrderProducts(ArrayList products)
    > {
    > ArrayList newList = new ArrayList();
    > IEnumerator eList = products.GetEnumerator();
    > while(eList.MoveNext())
    > {
    > Product item = (Product)(eList.Current);
    > // DO whatever, f.i. updating each product...
    > newList.Add(item);
    > }
    > //Return Updated Products
    > return newList;
    > }
    > }
    > } (I have not tested this sample, just wrote it like it can be)
    >
    > So, it depends of your scenario.
    > Of course, if all you have is .NET and you are starting with WebServices,
    > DataSets and ArrayLists are really easy.
    >
    > --
    > CESAR DE LA TORRE
    > Software Architect
    > [Microsoft MVP - XML Web Services]
    > [MCSE] [MCT]
    >
    > Renacimiento
    > [Microsoft GOLD Certified Partner]
    >
    >
    > "Arjen" wrote:
    >
    >> Hi,
    >>
    >> I want to make a webservice that returns an order with orderlines.
    >> How can this be best done?
    >>
    >> Can this be done with an object order (class order) that haves a property
    >> arraylist of orderline objects (class orderline)?
    >>
    >> Hope someone can help, thanks!
    >>
    >>
    >>
    Arjen, Oct 18, 2005
    #3
  4. The problem deals with data-types (serializable or not serializable &
    interoperable or not interoperable). When talking about interoperability, it
    does no matter if you have multiple orders or orderlines but it DOES matter
    what kind of Data-Types you are using.
    --
    CESAR DE LA TORRE
    Software Architect
    [Microsoft MVP - XML Web Services]
    [MCSE] [MCT]

    Renacimiento
    [Microsoft GOLD Certified Partner]


    "Arjen" wrote:

    > Okay, thanks!
    >
    > Maybe I will use method 3... split up orders and orderlines.
    >
    > What happens when I want to return multiple orders or orderlines?
    > Do I get the same problem (array?)?
    >
    > Thanks!
    >
    >
    >
    > "CESAR DE LA TORRE [MVP]" <> schreef in bericht
    > news:...
    > > It depends of what you have (or could have) on the other side... I mean,
    > > all
    > > the app.consumers are .NET based or thay could be from any other platform
    > > like Java?
    > > ------------
    > > A.- METHOD ONE.
    > > If you have .NET on both end-points (WS and cosumer) you can use DataSets
    > > (because DataSets are automatically serialized to XML), within that
    > > DataSet,
    > > one DataTable could be for the main Order and another DataTable could be
    > > for
    > > Order details. This is the easiest way to do it with .NET.
    > > To do so, just return a DataSet as a return function value from your
    > > WebMethod and get it from the consumer App. It is straight forward and
    > > extremely easy.
    > > BUT, using DataSets have several handicaps:
    > > 1.- You'll have interoperability problem if you want to consume your
    > > WebService from any other platform like Java, because of DataSet's Schema
    > > issues. Take into account that .NET DataSets (like Vectors in Java) are
    > > platform specific types that can't be represented easily in other
    > > platforms.
    > > This is because there is currently no single well-defined mapping between
    > > such platform-specific types and XML. Just because a .NET client can
    > > recognize a blob of XML as a Dataset, it doesn't mean a Web service client
    > > written in Java can do the same. Interoperability problems arise as a
    > > result.
    > > 2.- Depending of your bandwidth, DataSets are a bit heavy (big XML
    > > structures).
    > > ----------
    > > B.- METHOD TWO.
    > > The other way is to use plain Clasess and structures, and define first
    > > your
    > > WSDL (it is called "Contract First"), and serializing those clasess using
    > > Attributes, etc. This way, you'll have to work a little bit more (more
    > > programming) but because you are defining "The Contract First" (WSDL), it
    > > will be interoperable with any other platform like Java. It also will have
    > > more performance because SOAP messages will likely have a lighter schema
    > > and
    > > XML.
    > > To use plain classes ans serializing by your self, take a look to this
    > > URL:
    > > - Exposing custom-made classes through a Webservice and binding them to a
    > > DataGrid
    > > http://www.codeproject.com/vb/net/leaditwebservicewrapper.asp
    > > This is a really nice article.
    > > And:
    > > - Contract First Web Services Interoperability between Microsoft .NET and
    > > IBM WebSphere:
    > > http://msdn.microsoft.com/vstudio/java/interop/websphereinterop/default.aspx
    > >
    > > BTW, about your question (using ArrayLists), here you have an example. BUT
    > > using ArrayLists IS NOT INTEROPERABLE either. If all you have is .NET,
    > > great.
    > > But if you have Java on the other point..., you'll have problems:
    > >
    > > namespace Orders
    > > {
    > > [WebService(Namespace="http://services.orders")]
    > > public class OrdersService: WebService
    > > {
    > >
    > > public struct Product {
    > > public string name;
    > > public int qty;
    > > public float price;
    > > }
    > >
    > > [WebMethod]
    > > [XmlInclude(typeof(Product))]
    > > public ArrayList updateOrderProducts(ArrayList products)
    > > {
    > > ArrayList newList = new ArrayList();
    > > IEnumerator eList = products.GetEnumerator();
    > > while(eList.MoveNext())
    > > {
    > > Product item = (Product)(eList.Current);
    > > // DO whatever, f.i. updating each product...
    > > newList.Add(item);
    > > }
    > > //Return Updated Products
    > > return newList;
    > > }
    > > }
    > > } (I have not tested this sample, just wrote it like it can be)
    > >
    > > So, it depends of your scenario.
    > > Of course, if all you have is .NET and you are starting with WebServices,
    > > DataSets and ArrayLists are really easy.
    > >
    > > --
    > > CESAR DE LA TORRE
    > > Software Architect
    > > [Microsoft MVP - XML Web Services]
    > > [MCSE] [MCT]
    > >
    > > Renacimiento
    > > [Microsoft GOLD Certified Partner]
    > >
    > >
    > > "Arjen" wrote:
    > >
    > >> Hi,
    > >>
    > >> I want to make a webservice that returns an order with orderlines.
    > >> How can this be best done?
    > >>
    > >> Can this be done with an object order (class order) that haves a property
    > >> arraylist of orderline objects (class orderline)?
    > >>
    > >> Hope someone can help, thanks!
    > >>
    > >>
    > >>

    >
    >
    >
    CESAR DE LA TORRE [MVP], Oct 19, 2005
    #4
    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. Russ Perry Jr
    Replies:
    2
    Views:
    4,104
    Russ Perry Jr
    Aug 20, 2004
  2. Chad E. Dollins
    Replies:
    3
    Views:
    648
    Kai-Uwe Bux
    Nov 8, 2005
  3. request@no_spam.com
    Replies:
    5
    Views:
    415
  4. 7stud
    Replies:
    11
    Views:
    676
    Dennis Lee Bieber
    Mar 20, 2007
  5. Ultrus
    Replies:
    3
    Views:
    365
    Stefan Behnel
    Jul 9, 2007
Loading...

Share This Page