首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >wsimport不生成与soap标头相关的代码

wsimport不生成与soap标头相关的代码
EN

Stack Overflow用户
提问于 2011-08-31 21:24:32
回答 2查看 10.5K关注 0票数 20

我正在使用'wsimport‘从wsdl生成客户端java代码。wsdl在操作定义中有soap:header,如下所示

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://www.test.com/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" targetNamespace="http://www.test.com/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
  <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Test session web service methods.</wsdl:documentation>
  <wsdl:types>
    <s:schema elementFormDefault="qualified" targetNamespace="http://www.test.com/">
      <s:element name="Logon">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="user" type="s:string" />
            <s:element minOccurs="0" maxOccurs="1" name="password" type="s:string" />
            <s:element minOccurs="0" maxOccurs="1" name="organisation" type="s:string" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="LogonResponse">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="1" maxOccurs="1" name="LogonResult" type="tns:LogonResult" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:simpleType name="LogonResult">
        <s:restriction base="s:string">
          <s:enumeration value="Ok" />
          <s:enumeration value="Error" />
        </s:restriction>
      </s:simpleType>
      <s:element name="Header" type="tns:Header" />
      <s:complexType name="Header">
        <s:sequence>
          <s:element minOccurs="0" maxOccurs="1" name="SessionID" type="s:string" />
        </s:sequence>
        <s:anyAttribute />
      </s:complexType>
      <s:element name="RunTask">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="argument" type="s:string" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="RunTaskResponse">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="1" maxOccurs="1" name="RunTaskResult" type="tns:RunTaskResult" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:simpleType name="RunTaskResult">
        <s:restriction base="s:string">
          <s:enumeration value="Ok" />
          <s:enumeration value="Error" />
        </s:restriction>
      </s:simpleType>
    </s:schema>
  </wsdl:types>
  <wsdl:message name="LogonSoapIn">
    <wsdl:part name="parameters" element="tns:Logon" />
  </wsdl:message>
  <wsdl:message name="LogonSoapOut">
    <wsdl:part name="parameters" element="tns:LogonResponse" />
  </wsdl:message>
  <wsdl:message name="LogonHeader">
    <wsdl:part name="Header" element="tns:Header" />
  </wsdl:message>
  <wsdl:message name="RunTaskSoapIn">
    <wsdl:part name="parameters" element="tns:RunTask" />
  </wsdl:message>
  <wsdl:message name="RunTaskSoapOut">
    <wsdl:part name="parameters" element="tns:RunTaskResponse" />
  </wsdl:message>
  <wsdl:message name="RunTaskHeader">
    <wsdl:part name="Header" element="tns:Header" />
  </wsdl:message>
  <wsdl:portType name="SessionSoap">
    <wsdl:operation name="Logon">
      <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Logs on with the user credentials.</wsdl:documentation>
      <wsdl:input message="tns:LogonSoapIn" />
      <wsdl:output message="tns:LogonSoapOut" />
    </wsdl:operation>
    <wsdl:operation name="RunTask">
      <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Runs a task.</wsdl:documentation>
      <wsdl:input message="tns:RunTaskSoapIn" />
      <wsdl:output message="tns:RunTaskSoapOut" />
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="SessionSoap" type="tns:SessionSoap">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
    <wsdl:operation name="Logon">
      <soap:operation soapAction="http://www.test.com/Logon" style="document" />
      <wsdl:input>
        <soap:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal" />
        <soap:header message="tns:LogonHeader" part="Header" use="literal" />
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="RunTask">
      <soap:operation soapAction="http://www.test.com/RunTask" style="document" />
      <wsdl:input>
        <soap:body use="literal" />
        <soap:header message="tns:RunTaskHeader" part="Header" use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="Session">
    <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Test session web service methods.</wsdl:documentation>
    <wsdl:port name="SessionSoap" binding="tns:SessionSoap">
      <soap:address location="https://login.test.com/webservices/session.asmx" />
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

这表示请求登录消息将如下所示

代码语言:javascript
复制
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XmlSchema-instance" xmlns:xsd="http://www.w3.org/2001/XmlSchema">
  <soap:Body>
    <Logon xmlns="http://www.test.com/">
      <user>its_me</user>
      <password>its_my_pwd</password>
      <organisation>my_org</organisation>
    </Logon>
  </soap:Body>
</soap:Envelope>

结果是这样的

代码语言:javascript
复制
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Header>
    <Header xmlns="http://www.test.com/">
      <SessionID>ddffdf334-217d-41bb-9d7e-6289fefa8aaf</SessionID>
    </Header>
  </soap:Header>
  <soap:Body>
    <LogonResponse xmlns="http://www.test.com/">
      <LogonResult>Ok</LogonResult>
    </LogonResponse>
  </soap:Body>
</soap:Envelope>
EN

回答 2

Stack Overflow用户

发布于 2014-07-07 13:23:17

我无法评论,所以我在这里写这篇文章作为一个“答案”。

我遇到了同样的情况,信封里只有身体。然而,在添加了'-XadditionalHeaders‘参数之后,wsimport仍然拒绝生成带有头参数的服务方法。我在互联网上搜索,在下面的链接中找到了一个手册补丁:

https://metro.java.net/2.0/guide/SOAP_headers.html

我没有在代码中这样做。相反,我更改了web服务操作方法的方法签名,方法是为请求标头添加参数并用@WebParam(header=true)注释它们。我没有在真正的web服务服务器上测试过它,但至少SOAP消息现在看起来是正确的(不再是无头的)。

票数 1
EN

Stack Overflow用户

发布于 2016-06-16 03:52:02

-exsh (true/false)

启用或禁用隐式SOAP标头(即wsdl:binding中定义的SOAP标头,但不是wsdl:portType部分中定义的SOAP标头)的处理。处理SOAP头需要类路径上可用的SOAP绑定jars,这在CXF2.4.x和更早的版本中不是默认的。您可能需要向cxf-rt-binding-soap添加一个依赖项才能使此标志起作用。默认值为false。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7257539

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档