Metro 客户端使用 WCF wsdl,未设置响应对象的属性

发布于 2024-12-07 05:04:57 字数 5854 浏览 3 评论 0原文

我正在尝试使用 JAX-WS 和 Metro 库从 Java 客户端使用 WCF Web 服务。我已经使用 wsimport 成功生成了客户端,并且可以打开与服务器的会话,但是服务返回的会话令牌未设置到 Java 的响应对象中。然后,当我将空字符串传递到 endSession 时,该服务会返回错误,而 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 为空。我已确定 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;
  }

}

当然还有其他操作,但我只发布了相关的操作和类型。

有没有人有足够的地铁经验来告诉我我忘记了哪个愚蠢的设置? 谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一梦浮鱼 2024-12-14 05:04:57

已修复,Web 服务不在响应中提供命名空间信息。当响应如下所示时,它就可以正常工作:

<SessionTokenResponse xmlns="http://My.Namespace">
  <Errors />
  <Messages />
  <Warnings />
  <SessionToken>e579dd3e-34df-4396-ae42-1ebf03c9f301</SessionToken>
</SessionTokenResponse>

Fixed, the web service was not providing namespace information in the response. When the response looks like the following then it works fine:

<SessionTokenResponse xmlns="http://My.Namespace">
  <Errors />
  <Messages />
  <Warnings />
  <SessionToken>e579dd3e-34df-4396-ae42-1ebf03c9f301</SessionToken>
</SessionTokenResponse>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文