wsimport不会生成与soap标头相关的代码 [英] wsimport doesnt generate code related to soap headers

查看:38
本文介绍了wsimport不会生成与soap标头相关的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用'wsimport'从wsdl生成客户端java代码。 wsdl在这样的操作定义中有soap:header

I'm generating client java code from a wsdl using 'wsimport'. The wsdl has soap:header in the operation definitions like this

<?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>

这表示请求登录消息看起来像这样

This indicates that a request logon message would look like this

<?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>

和这样的回复

<?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>


推荐答案

我无法评论所以我在这里写这个一个答案。

I could not comment so I am writing this here as an "answer".

我遇到了信封中只有身体的情况。但是在添加'-XadditionalHeaders'参数后,wsimport仍然拒绝使用头参数生成服务方法。我在互联网上搜索并在以下链接中找到了一个手动补丁:

I ran into the same situation where there was only body in the envelope. However after adding the '-XadditionalHeaders' argument, wsimport still refused to generate service methods with header arguments. I searched on the Internet and found a manual patch in the following link:

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

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

I did not do it in the code. Instead I changed the method signature of the web service operation method by adding arguments for the request header and annotating them with @WebParam(header=true). I have not tested it with a real web service server, but at least the SOAP message now looks correct (no longer headless).

这篇关于wsimport不会生成与soap标头相关的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆