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 said:
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!