views:

663

answers:

1

I am a bit rusty in my Java, and this is my first time using metro/JAX-WS, so if this is a dumb question I apologize.

I have to write a client that consumes a .NET webservice. I've got the basics down; I have generated the wrappers from the WSDL, and I can create my object and port and make a call and get a response.

 Widgets d = new Widgets();
 WidgetsSoap dp = d.getWidgetsSoap();
 ((BindingProvider)dp).getRequestContext(). put(javax.xml.ws.BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://actualsite/foo.asmx");

 UserGetWidgetsResponse.UserGetWidgetsResult j = dp.userGetWidgets();

The webservice's return values are almost all XmlDocument or XmlNode. How do I get from the wsimport-generated "UserGetWidgetsResponse.UserGetWidgetsResult" to the actual XML returned by the call?

I have a number of these services with a bunch of methods, so I'm hoping to find a solution that does not require modifying the generated wrappers in any way. I also do not have control over the information returned by the web services.

+1  A: 

I found a solution to this over the weekend, but I'm not sure it's the right solution:

 UserGetDevicesResponse.UserGetDevicesResult j = dp.userGetDevices();
 List<Object> n = j.getContent();
 if (n.size() > 0)
 {
  Node z = (Node)n.get(0);
  System.out.println(nodeToString(z));
 }

This gives me the XML document response, which is what I was looking for. I can then do whatever operations I want on the tree to extract the data I'm looking for.

Joe