2011-08-31 64 views
17

我使用'wsimport'從wsdl生成客戶端java代碼。該WSDL有肥皂:頭在這樣wsimport不會生成肥皂標題相關的代碼

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

這表明,請求登錄消息是這樣的

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

耶,我自己找到了。將選項'-XadditionalHeaders'添加到wsimport命令解決了問題。它爲可以通過/檢索標題的方法生成額外的參數。我沒有刪除該問題,因爲我無法在堆棧溢出中找到此解決方案,因此可能有用 – thehpi

+1

謝謝! .. ps:這是在谷歌上的「wsimport設置標題」的熱門! –

回答

1

我的響應操作定義無法評論,所以我在這裏寫作這個「答案」。

我遇到了同樣的情況,信封裏只有身體。但是,在添加'-XadditionalHeaders'參數後,wsimport仍然拒絕使用頭部參數生成服務方法。我在互聯網上搜索,發現一個手動跳線在以下鏈接:

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

真的不是我的代碼。相反,我通過添加請求標題的參數並使用@WebParam(header=true)註釋它們來更改Web服務操作方法的方法簽名。我沒有用真正的Web服務服務器對它進行測試,但至少現在看起來SOAP消息是正確的(不再是無頭的)。

0

-exsh(真/假)

啓用或禁用隱式SOAP頭的處理(在WSDL中定義即SOAP標頭:結合,但不WSDL:portType的部分)處理的SOAP標頭需要SOAP綁定罐子在類路徑中可用,這不是CXF 2.4.x及更早版本中的默認路徑。您可能需要爲cxf-rt-binding-soap添加一個依賴項,以使此標誌起作用。默認爲false。