I have to consume a .NET hosted web service from a Java application. Interoperability between the two is usually very good. The problem I'm running into is that the .NET application developer chose to expose data using the .NET DataSet object. There are lots of articles written as to why you should not do this and how it makes interoperability difficult:
My problem is that despite this not being recommended practice, I am stuck with having to consume a web service returning a DataSet with Java. When you generate a proxy for something like this with anything other than .NET you basically end up with an object that looks like this:
@XmlElement(namespace = "http://www.w3.org/2001/XMLSchema", required = true)
protected Schema schema;
@XmlAnyElement(lax = true)
protected Object any;
This first field is the actual schema that should describe the DataSet. When I process this using JAX-WS and JAXB in Java, it bring all of XS-Schema in as Java objects to be represented here. Walking the object tree of JAXB is possible but not pretty. The any field represents the raw XML for the DataSet that is in the schema specified by the schema.
The structure of the dataset is pretty consistent but the data types do change. I need access to the type information and the schema does vary from call to call. I've though of a few options but none seem like 'good' options.
Are there other options I have not considered? Is there a Java library to parse DataSet objects easily? What have other people done who may have similar situations?
Unfortunately I don't think there's an easy answer here. What I would do is create a Proxy web service in .NET that you could call from Java that would receive the dataset, transform it into something more consumable and then return that to your Java code.
Is your Java application running on a server? If so, install Mono on the server and use ADO.NET built into Mono to convert the Dataset into something Java can understand. The advantage is that all the interpretation of the Dataset is done for you in Mono. You can even use IKVM to stay in the Java language world. Anyway, in the Mono world you can have a local service which can do the conversion, or simply have a utility that converts the Dataset into the file system in a format that Java can understand.
Have you considered using XSLT on the raw XML returned to massage it into something you can handle more easily?
I've used that approach to convert a complex return value into something similar to
<ops>
<set name="foo" value="bar"/>
<set name="foo2" value="bar2" />
....
</ops>
This moves the logic into a language well suited to process XML instead of handcoding it in Java.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With