我正在尝试使用JAX-WS和Metro库从Java客户端使用WCF Web服务。我已经使用wsimport成功生成了客户端,并且可以打开与服务器的会话,但是服务返回的会话令牌没有被设置为Java的响应对象。然后,当我将空字符串传递给endSession时,服务会返回一个错误,当它期望SessionToken时,它会发送一条没有正文内容的消息。
这是我的'main()'方法的要点
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());
}
我得到的错误是会话对象中的sessionToken为null。我已经确定sessionToken永远不会被设置。我无法进入beginSession方法,因为端口是动态生成的代理。
我发送的请求是:
<?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>
我收到的回复是:
<?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>
在WSDL中,我的SessionTokenResponse对象定义如下:
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;
}
}
当然还有其他操作,但我只发布了相关的操作和类型。
有没有人有过Metro的经验,足以告诉我忘记了哪个愚蠢的设置? 感谢
答案 0 :(得分:0)
已修复,Web服务未在响应中提供命名空间信息。如果响应如下所示,那么它可以正常工作:
<SessionTokenResponse xmlns="http://My.Namespace">
<Errors />
<Messages />
<Warnings />
<SessionToken>e579dd3e-34df-4396-ae42-1ebf03c9f301</SessionToken>
</SessionTokenResponse>