Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Services > Nested objects?

Reply
Thread Tools

Nested objects?

 
 
Arjen
Guest
Posts: n/a
 
      10-18-2005
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!


 
Reply With Quote
 
 
 
 
CESAR DE LA TORRE [MVP]
Guest
Posts: n/a
 
      10-18-2005
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/le...icewrapper.asp
This is a really nice article.
And:
- Contract First Web Services Interoperability between Microsoft .NET and
IBM WebSphere:
http://msdn.microsoft.com/vstudio/ja...p/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!
>
>
>

 
Reply With Quote
 
 
 
 
Arjen
Guest
Posts: n/a
 
      10-18-2005
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]" <(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed)...
> 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/le...icewrapper.asp
> This is a really nice article.
> And:
> - Contract First Web Services Interoperability between Microsoft .NET and
> IBM WebSphere:
> http://msdn.microsoft.com/vstudio/ja...p/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!
>>
>>
>>



 
Reply With Quote
 
CESAR DE LA TORRE [MVP]
Guest
Posts: n/a
 
      10-18-2005
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]" <(E-Mail Removed)> schreef in bericht
> news:(E-Mail Removed)...
> > 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/le...icewrapper.asp
> > This is a really nice article.
> > And:
> > - Contract First Web Services Interoperability between Microsoft .NET and
> > IBM WebSphere:
> > http://msdn.microsoft.com/vstudio/ja...p/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!
> >>
> >>
> >>

>
>
>

 
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
Nested friend class in nested template problem tonvandenheuvel@gmail.com C++ 3 12-07-2007 03:02 PM
dealing with nested xml within nested xml within...... Ultrus Python 3 07-09-2007 09:00 PM
Is nested class automatically friend of class that it is nested in? request@no_spam.com C++ 5 09-25-2006 08:31 AM
Nested Vector Nester Classes are Nested in my Brain Chad E. Dollins C++ 3 11-08-2005 04:46 AM
Nested iterators (well, not nested exactly...) Russ Perry Jr Java 2 08-20-2004 06:51 PM



Advertisments