You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by to...@gsk.com on 2004/08/27 12:00:10 UTC
WSDL2Java and document/literal
Hi,
I have some WSDL that defines a service which takes no parameters but
which has a complex response object. The response object defines a list of
complex objects (which are not very complex in reality, with each object
having a few attributes of strings and ints). The WSDL2Java tool generates
all of the classes just fine, but there is nothing done to the incoming
response, which comes back as a raw XML SOAP body element. There is no
code that converts the response element to the list object that I want.
All the generated stub does is try to cast the response element (actually
a vector of soap body elements, with only one entry) to the class that was
generated for the response message. Consequently, a class cast exception
occurs.
Does anyone have any ideas what I might need to do, to get this to work,
other than write some XML parsing code?
Just to clarify ...
The response from the service call is a vector of RPCElement instances (an
Axis class). There is only one element in the vector, as expected. The
single element, an RPCElement, is the XML of the expected response. The
XML defines a list of other elements, each of which has a few simple
attributes. The relevant generated stub code looks something like this:
java.lang.Object _resp = _call.invoke(new java.lang.Object[]
{myServiceCall});
if (_resp instanceof java.rmi.RemoteException) {
throw (java.rmi.RemoteException)_resp;
}
else {
extractAttachments(_call);
try {
return (myResponseClass) _resp;
} catch (java.lang.Exception _exception) {
return (myResponseClass)
org.apache.axis.utils.JavaUtils.convert(_resp, myResponseClass);
}
}
The _resp object is the vector of RPCElements. The myReponseClass is the
class generated from my WSDL response message definition. The cast is
always bound to fail, and the JavaUtils.convert call is only designed to
convert between collections (which my response message class isn't). I
feel sure that I'm not doing something I need to, since can't see how
this could ever work for anyone.
I tried the generator that comes with Sun's JWSDK and this seems to work
OK, though I haven't delved into the innards yet, so don't know what the
differences are.
Cheers,
Tony
Re: WSDL2Java and document/literal
Posted by to...@gsk.com.
Don't worry; I think I've figured this out.
I had assumed that an object needed to be passed to the method in the
generated stub. The actual web service implementation doesn't need a
parameter but the generated stub method takes an object. I'm new to this
but managed to find some reference to a Soap body element and decided to
create one of these to pass in. This worked, so far as the web service
call is concerned. However, it caused Axis to use messaging, rather than
RPC. This, in turn, resulted in a response object that was a vector of
SOAP body elements, which wasn't what was expected.
When I simply passed a null to the generated stub method it all worked
wonderfully, since the object returned from the service call invoke method
was the Java object I expected all along. I don't yet understand the
detail of all this but it now works fine. I'm not sure why Sun's JWSDK
handled this OK and Axis didn't but I'll leave that for another day.
Cheers,
Tony