2011-08-31 25 views
17

Tôi đang tạo mã java của khách hàng từ wsdl bằng 'wsimport'. Các wsdl có xà phòng: tiêu đề trong các định nghĩa hoạt động như thế nàywsimport không tạo mã liên quan đến tiêu đề xà phòng

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

Điều này cho thấy một thông điệp yêu cầu đăng nhập sẽ trông như thế này

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

và phản ứng như thế này

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

Yay, tôi tự tìm thấy. Thêm tùy chọn '-XadditionalHeaders' vào lệnh wsimport đã giải quyết được vấn đề. Nó tạo ra một đối số bổ sung cho phương thức mà qua đó tiêu đề có thể được truyền/lấy ra. Tôi đã không xóa câu hỏi bởi vì tôi đã không thể tìm thấy giải pháp này trên ngăn xếp tràn và như vậy có thể hữu ích – thehpi

+1

Cảm ơn! .. ps: Đây là hit hàng đầu cho "tiêu đề thiết lập wsimport" trên google! –

Trả lời

1

tôi không thể bình luận vì vậy tôi viết bài này ở đây như là một "câu trả lời".

Tôi gặp phải tình huống tương tự khi chỉ có nội dung trong phong bì. Tuy nhiên sau khi thêm đối số '-XadditionalHeaders', wsimport vẫn từ chối tạo các phương thức dịch vụ với các đối số tiêu đề. Tôi đã tìm kiếm trên Internet và tìm thấy một bản vá thủ công trong liên kết sau:

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

tôi không làm điều đó trong các mã. Thay vào đó, tôi đã thay đổi chữ ký phương thức của phương thức hoạt động dịch vụ web bằng cách thêm đối số cho tiêu đề yêu cầu và chú thích chúng bằng @WebParam(header=true). Tôi đã không thử nghiệm nó với một máy chủ dịch vụ web thực sự, nhưng ít nhất là thông báo SOAP bây giờ trông chính xác (không còn không đầu).

0

-exsh (true/false)

Bật hoặc tắt chế biến tiêu đề SOAP ngầm (tức là tiêu đề SOAP định nghĩa trong wsdl: binding, thế nhưng không wsdl:. Phần portType) Chế biến các tiêu đề SOAP yêu cầu SOAP ràng buộc lọ có sẵn trên classpath không phải là mặc định trong CXF 2.4.x trở lên. Bạn có thể cần phải thêm một phụ thuộc vào cxf-rt-binding-soap để cờ này hoạt động. Mặc định là sai.

Các vấn đề liên quan