I am attempting to consume a WCF web service from a Java client using JAX-WS and the Metro libraries. I have successfully generated the client using wsimport, and can open a session with the server, however the session token being returned by the service is not being set into Java’s response object. The service then returns an error when I pass a null string into endSession which sends a message that has no body content when it expects the SessionToken.
Here is the gist of my ‘main()’ method
public static void main(String[] args) {
MyService service = new MyService()
MyPort port = service.getBasicHttpBinding();
EmulateRequest request = new EmulateRequest();
request.setUnimportantProperties();
SessionTokenResponse session = port.beginSessionAndEmulate(request);
port.endSession(session.getSessionToken());
}
The error I am getting is that the sessionToken in the session object is null. I have determined that the sessionToken is never set. I cannot step into the beginSession method because the port is a dynamically generated proxy.
The request I am sending is this:
<?xml version='1.0' encoding='UTF-8'?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<EmulateRequest xmlns="http://My.Namespace">
<UnimportantProperties>XXXX</UnimportantProperties>
</EmulateRequest>
</S:Body>
</S:Envelope>
And the response I receive is this:
<?xml version='1.0' encoding='UTF-8'?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<s:Header>
<o:Security xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:mustUnderstand="1">
<u:Timestamp u:Id="_0">
<u:Created>2011-09-30T17:49:38.570Z</u:Created>
<u:Expires>2011-09-30T17:54:38.570Z</u:Expires>
</u:Timestamp>
</o:Security>
</s:Header>
<s:Body>
<SessionTokenResponse>
<Errors />
<Messages />
<Warnings />
<SessionToken>e579dd3e-34df-4396-ae42-1ebf03c9f301</SessionToken>
</SessionTokenResponse>
</s:Body>
</s:Envelope>
In the WSDL, my SessionTokenResponse object is defined as the following:
xmlns:tns="http:\\MyNamespace"
<wsdl:types>
<xs:complexType name="SessionTokenResponse">
<xs:complexContent>
<xs:extension base="Response">
<xs:sequence>
<xs:element name="SessionToken" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="Response">
<xs:sequence>
<xs:element name="Errors">
<xs:complexType>
<xs:sequence>
<xs:element name="Error" minOccurs="0" maxOccurs="unbounded" type="Error"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Messages">
<xs:complexType>
<xs:sequence>
<xs:element name="Message" minOccurs="0" maxOccurs="unbounded" type="Message"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Warnings">
<xs:complexType>
<xs:sequence>
<xs:element name="Warning" minOccurs="0" maxOccurs="unbounded" type="Warning"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</wsdl:types>
<wsdl:message name="EmulateRequestMessage">
<wsdl:part name="EmulateRequest" element="tns:EmulateRequest"/>
</wsdl:message>
<wsdl:message name="SessionTokenResponseMessage">
<wsdl:part name="SessionTokenResponse" element="tns:SessionTokenResponse"/>
</wsdl:message>
<wsdl:portType msc:usingSession="false" name="MyPortName">
<wsdl:operation name="BeginSessionAndEmulate">
<wsdl:input wsaw:Action="http://MyNamespace/BeginSessionAndEmulate" name="EmulateRequestMessage" message="tns:EmulateRequestMessage"/>
<wsdl:output wsaw:Action="http://MyNamespace/BeginSessionAndEmulateResponse" name="SessionTokenResponseMessage" message="tns:SessionTokenResponseMessage"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="BasicHttpBinding" type="tns:MyBindingName">
<wsdl:operation name="BeginSessionAndEmulate">
<wsp:PolicyReference URI="#BasicHttpBinding_policy"/>
<wsdl:input name="EmulateRequestMessage">
<soap:body use="literal" parts="EmulateRequest"/>
</wsdl:input>
<wsdl:output name="SessionTokenResponseMessage">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="MyService">
<wsdl:port name="BasicHttpBinding" binding="tns:BasicHttpBinding">
<soap:address location="https://MyServiceLocation"/>
</wsdl:port>
</wsdl:service>
/** Generated by WsImport *************************************/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "SessionTokenResponse", propOrder = {
"sessionToken"
})
public class SessionTokenResponse
extends Response
{
@XmlElement(name = "SessionToken")
public String sessionToken;
public String getSessionToken() {
return sessionToken;
}
public void setSessionToken(String value) {
this.sessionToken = value;
}
}
There are of course other operations, but I have posted the relevant operation and types only.
Does anyone have experience with Metro enough to tell me which dumb setting I forgot?
Thanks
Fixed, the web service was not providing namespace information in the response. When the response looks like the following then it works fine: