A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.
Is there a way I can store return results from web services in datasets ?
I have a C# client that calls different web services running on different platforms and written in different languages. I have proxies generated through wsdl to access these web services. Now is there a way that I can store the results of these web service calls directly into datasets.
Here's an example:
Orders GetOrdersByCustomerId(string customerId)
is a web method written in Ruby.
it retuns an array of Orders objects for matching customer id. Now, is there a way to store these return result in Dataset on client side? I know there are methods for loading and saving xml to/from datasets. but how to achieve that in this scenario?
If your Order class is a flat structure (i.e. public fields are primitive types), you could write some code to:
- Create a DataSet with a single DataTable
- Use Reflection to get the data type and name of each public field in the class returned by the WS (Order in your case)
- Add a DataColumn to your DataTable for each public field in the object returned by the WS (Order in your case). To make the code generic you can use reflection to get the type and name of each public field (GetFields method I think).
- Iterate through the array returned by the WS: for each object add a row to your DataTable. Get the values of each public field using reflection.
By using reflection you could have a generic method that would work with most 'flat' object arrays.
If the structure is more complex (e.g. Order object contains a collection of OrderLine objects) it gets a bit more complicated, you have to add additional DataTables and releations.
Thursday, March 30, 2006
This topic is archived. No further replies will be accepted.Other recent topics
Powered by FogBugz