tags:

views:

138

answers:

4

i am using webservice.i am getting data to java in the form of C# dataset how to retrive values from dataset in java please help it's very urgent

A: 

It depends on the format of the webservice. If it's a SOAP service look to a prior SO answer: consuming-a-web-service-in-java

If it's restful. I'd suggest using JSON if possible because the JSON serializer on the .Net side generally gives you a more agnostic serialization. Then, Java-side httpclient gives you a robust way to connect, and Json-lib lets you parse, rock, and roll.

anq
+1  A: 

Does this mean you are using the web service to transport the actual DataSet object?

Just convert the C# data set to xml or a formatted string on the C# side before it gets sent to the web service. Then you can easily re-parse the web service output into whatever java object you want. (I would just go with a formatted string, I havent used any Java XML libraries that come CLOSE to being as good as C#'s XDoc).

jdc0589
+1  A: 

A dataset is serialized as XML. You will have to create an XML object on the Java side and consume it by binding the XML to items in your application. For simple report output, XSLT would help to simply the work.

or

Try to stay away from anything that's .NET-specific. Don't return a DataSet, for instance. Stick to using simple types, arrays and structs of simple types, and you'll be fine.

Happy coding

Ravia
Didn't know it was serialized that way, good to know.
jdc0589
actuallly i am working on android there i am using ksoap2 webservices and i am getting data from server that should return only dataset
Aswan
A: 

I've handled this by using XPath with Xalan to query the DOM document that Axis hands to me. The schema of the serialized DataSet is pretty clear and easy to query. I just had to be sure to set up Xalan with the proper namespaces to perform the queries.

I ran into one problem handing the data this way. The serialized DataSet doesn't contain an element for data that is null. If you know what data you are expecting then this isn't a problem. However, if you don't know exactly what data to expect, you can extract the fields that are in the DataSet from the XML document.

iboisver