2014-12-04 29 views
0

我想我們的Java的春季應用程序集成到客戶端系統。客戶端系統需要調用我們的一個SOAP Web服務來提供數據。他們已經有了一個系統,我們將會取代它。客戶端還沒準備好進行任何更改,並要求我們使用與現在相同的格式。當我們嘗試使用Apache Axis的1,它的捐贈和額外<item>標籤生成WSDL,並重復該標籤代替刪除<item>標籤數組複雜類型在Apache軸wsdl

他們提供的現有WSDL如下

<?xml version="1.0" encoding="utf-8"?> 
<wsdl:definitions xmlns:s0="http://danateq.com/soap/link/eventgateway" 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://eventIndication" 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://eventIndication" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"> 
    <wsdl:types> 
    <s:schema elementFormDefault="qualified" targetNamespace="http://danateq.com/soap/link/eventgateway"> 
     <s:import /> 
     <s:element name="EventIndication" type="s0:Input" /> 
     <s:complexType name="Input"> 
     <s:sequence> 
      <s:element minOccurs="0" maxOccurs="1" ref="UserID" /> 
      <s:element minOccurs="0" maxOccurs="1" ref="UserIDType" /> 
      <s:element minOccurs="0" maxOccurs="1" ref="OrigPlatformID" /> 
      <s:element minOccurs="0" maxOccurs="1" ref="OrigPlatformNode" /> 
      <s:element minOccurs="0" maxOccurs="1" ref="EventID" /> 
      <s:element minOccurs="0" maxOccurs="unbounded" ref="Parameter" /> 
     </s:sequence> 
     </s:complexType> 
    </s:schema> 
    <s:schema elementFormDefault="qualified"> 
     <s:element name="UserID" type="s:string" /> 
     <s:element name="UserIDType" type="s:string" /> 
     <s:element name="OrigPlatformID" type="s:string" /> 
     <s:element name="OrigPlatformNode" type="s:string" /> 
     <s:element name="EventID" type="s:string" /> 
     <s:element name="Parameter" type="tParameter" /> 
     <s:complexType name="tParameter"> 
     <s:sequence> 
      <s:element minOccurs="1" maxOccurs="1" name="ParameterType" type="s:int" /> 
      <s:element minOccurs="0" maxOccurs="1" name="ParameterValue" type="s:string" /> 
     </s:sequence> 
     </s:complexType> 
    </s:schema> 
    </wsdl:types> 
    <wsdl:message name="EventIndicationSoapIn"> 
    <wsdl:part name="EventIndication" element="s0:EventIndication" /> 
    </wsdl:message> 
    <wsdl:message name="EventIndicationSoapOut" /> 
    <wsdl:portType name="PointsService2Soap"> 
    <wsdl:operation name="EventIndication"> 
     <wsdl:input message="tns:EventIndicationSoapIn" /> 
     <wsdl:output message="tns:EventIndicationSoapOut" /> 
    </wsdl:operation> 
    </wsdl:portType> 
    <wsdl:binding name="PointsService2Soap" type="tns:PointsService2Soap"> 
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" /> 
    <wsdl:operation name="EventIndication"> 
     <soap:operation soapAction="http://EventIndication" style="document" /> 
     <wsdl:input> 
     <soap:body use="literal" /> 
     </wsdl:input> 
     <wsdl:output> 
     <soap:body use="literal" /> 
     </wsdl:output> 
    </wsdl:operation> 
    </wsdl:binding> 
    <wsdl:binding name="PointsService2Soap12" type="tns:PointsService2Soap"> 
    <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" /> 
    <wsdl:operation name="EventIndication"> 
     <soap12:operation soapAction="http://EventIndication" style="document" /> 
     <wsdl:input> 
     <soap12:body use="literal" /> 
     </wsdl:input> 
     <wsdl:output> 
     <soap12:body use="literal" /> 
     </wsdl:output> 
    </wsdl:operation> 
    </wsdl:binding> 
    <wsdl:service name="PointsService2"> 
    <wsdl:port name="PointsService2Soap" binding="tns:PointsService2Soap"> 
     <soap:address location="http://loyaltydev/Loyaltyws/PointsService2.asmx" /> 
    </wsdl:port> 
    <wsdl:port name="PointsService2Soap12" binding="tns:PointsService2Soap12"> 
     <soap12:address location="http://loyaltydev/Loyaltyws/PointsService2.asmx" /> 
    </wsdl:port> 
    </wsdl:service> 
</wsdl:definitions> 

SOAP請求實際陣列參數上述WSDL是

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:even="http://danateq.com/soap/link/eventgateway"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <even:EventIndication> 
     <!--Optional:--> 
     <UserID>?</UserID> 
     <!--Optional:--> 
     <UserIDType>?</UserIDType> 
     <!--Optional:--> 
     <OrigPlatformID>?</OrigPlatformID> 
     <!--Optional:--> 
     <OrigPlatformNode>?</OrigPlatformNode> 
     <!--Optional:--> 
     <EventID>?</EventID> 
     <!--Zero or more repetitions:--> 
     <Parameter> 
      <ParameterType>?</ParameterType> 
      <!--Optional:--> 
      <ParameterValue>?</ParameterValue> 
     </Parameter> 
     </even:EventIndication> 
    </soapenv:Body> 
</soapenv:Envelope> 

使用該WSDL我們已經產生使用的WSDL2Java(Apache的軸1.1)的對象。現在問題開始時,我們嘗試使用這些類生成Web服務。使用Apache Axis是如下

<?xml version="1.0" encoding="UTF-8"?> 
<wsdl:definitions targetNamespace="http://webservices.api.inspirenetz.com" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://webservices.api.inspirenetz.com" xmlns:intf="http://webservices.api.inspirenetz.com" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
<!--WSDL created by Apache Axis version: 1.4 
Built on Apr 22, 2006 (06:55:48 PDT)--> 
<wsdl:types> 
    <schema elementFormDefault="qualified" targetNamespace="http://webservices.api.inspirenetz.com" xmlns="http://www.w3.org/2001/XMLSchema"> 
    <complexType name="TParameter"> 
    <sequence> 
    <element name="parameterType" type="xsd:int"/> 
    <element name="parameterValue" nillable="true" type="xsd:string"/> 
    </sequence> 
    </complexType> 
    <complexType name="ArrayOfTParameter"> 
    <sequence> 
    <element maxOccurs="unbounded" minOccurs="0" name="item" type="impl:TParameter"/> 
    </sequence> 
    </complexType> 
    <complexType name="Input"> 
    <sequence> 
    <element name="eventID" nillable="true" type="xsd:string"/> 
    <element name="origPlatformID" nillable="true" type="xsd:string"/> 
    <element name="origPlatformNode" nillable="true" type="xsd:string"/> 
    <element name="parameter" nillable="true" type="impl:ArrayOfTParameter"/> 
    <element name="userID" nillable="true" type="xsd:string"/> 
    <element name="userIDType" nillable="true" type="xsd:string"/> 
    </sequence> 
    </complexType> 
    <element name="input" type="impl:Input"/> 
    <element name="EventIndicationReturn" type="xsd:string"/> 
    </schema> 
</wsdl:types> 

    <wsdl:message name="EventIndicationResponse"> 

     <wsdl:part element="impl:EventIndicationReturn" name="EventIndicationReturn"> 

     </wsdl:part> 

    </wsdl:message> 

    <wsdl:message name="EventIndicationRequest"> 

     <wsdl:part element="impl:input" name="input"> 

     </wsdl:part> 

    </wsdl:message> 

    <wsdl:portType name="FastdataWebService"> 

     <wsdl:operation name="EventIndication" parameterOrder="input"> 

     <wsdl:input message="impl:EventIndicationRequest" name="EventIndicationRequest"> 

     </wsdl:input> 

     <wsdl:output message="impl:EventIndicationResponse" name="EventIndicationResponse"> 

     </wsdl:output> 

     </wsdl:operation> 

    </wsdl:portType> 

    <wsdl:binding name="FastdataWebServiceSoapBinding" type="impl:FastdataWebService"> 

     <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> 

     <wsdl:operation name="EventIndication"> 

     <wsdlsoap:operation soapAction=""/> 

     <wsdl:input name="EventIndicationRequest"> 

      <wsdlsoap:body use="literal"/> 

     </wsdl:input> 

     <wsdl:output name="EventIndicationResponse"> 

      <wsdlsoap:body use="literal"/> 

     </wsdl:output> 

     </wsdl:operation> 

    </wsdl:binding> 

    <wsdl:service name="FastdataWebServiceService"> 

     <wsdl:port binding="impl:FastdataWebServiceSoapBinding" name="FastdataWebService"> 

     <wsdlsoap:address location="http://localhost:8080/services/FastdataWebService"/> 

     </wsdl:port> 

    </wsdl:service> 

</wsdl:definitions> 

用於上述WSDL中的SOAP請求

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://webservices.api.inspirenetz.com"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <web:input> 
     <web:eventID>?</web:eventID> 
     <web:origPlatformID>?</web:origPlatformID> 
     <web:origPlatformNode>?</web:origPlatformNode> 
     <web:parameter> 
      <!--Zero or more repetitions:--> 
      <web:item> 
       <web:parameterType>?</web:parameterType> 
       <web:parameterValue>?</web:parameterValue> 
      </web:item> 
     </web:parameter> 
     <web:userID>?</web:userID> 
     <web:userIDType>?</web:userIDType> 
     </web:input> 
    </soapenv:Body> 
</soapenv:Envelope> 

生成正如你可以看到產生 的WSDL,原始請求具有的重複陣列(Parameter對象)表示爲

<!--Zero or more repetitions:--> 
<Parameter> 
    <ParameterType>?</ParameterType> 
    <!--Optional:--> 
    <ParameterValue>?</ParameterValue> 
</Parameter> 

但是使用Apache Axis生成所述一個得到了內部的額外<item>標籤是越來越重複

<web:parameter> 
    <!--Zero or more repetitions:--> 
    <web:item> 
     <web:parameterType>?</web:parameterType> 
     <web:parameterValue>?</web:parameterValue> 
    </web:item> 
</web:parameter> 

這裏不是重複參數標記,而是重複參數標記內的<item>標記。

我還提供類的輸入和參數爲基準

Input.java

@XmlAccessorType(XmlAccessType.FIELD) 
@XmlType(name = "Input", namespace = "http://danateq.com/soap/link/eventgateway", propOrder = { 
    "userID", 
    "userIDType", 
    "origPlatformID", 
    "origPlatformNode", 
    "eventID", 
    "parameter" 
}) 
public class Input { 

    @XmlElement(name = "UserID") 
    protected String userID; 
    @XmlElement(name = "UserIDType") 
    protected String userIDType; 
    @XmlElement(name = "OrigPlatformID") 
    protected String origPlatformID; 
    @XmlElement(name = "OrigPlatformNode") 
    protected String origPlatformNode; 
    @XmlElement(name = "EventID") 
    protected String eventID; 
    @XmlElement(name = "Parameter") 
    protected TParameter[] parameter; 

    /** 
    * Gets the value of the userID property. 
    * 
    * @return 
    *  possible object is 
    *  {@link String } 
    *  
    */ 
    public String getUserID() { 
     return userID; 
    } 

    /** 
    * Sets the value of the userID property. 
    * 
    * @param value 
    *  allowed object is 
    *  {@link String } 
    *  
    */ 
    public void setUserID(String value) { 
     this.userID = value; 
    } 

    /** 
    * Gets the value of the userIDType property. 
    * 
    * @return 
    *  possible object is 
    *  {@link String } 
    *  
    */ 
    public String getUserIDType() { 
     return userIDType; 
    } 

    /** 
    * Sets the value of the userIDType property. 
    * 
    * @param value 
    *  allowed object is 
    *  {@link String } 
    *  
    */ 
    public void setUserIDType(String value) { 
     this.userIDType = value; 
    } 

    /** 
    * Gets the value of the origPlatformID property. 
    * 
    * @return 
    *  possible object is 
    *  {@link String } 
    *  
    */ 
    public String getOrigPlatformID() { 
     return origPlatformID; 
    } 

    /** 
    * Sets the value of the origPlatformID property. 
    * 
    * @param value 
    *  allowed object is 
    *  {@link String } 
    *  
    */ 
    public void setOrigPlatformID(String value) { 
     this.origPlatformID = value; 
    } 

    /** 
    * Gets the value of the origPlatformNode property. 
    * 
    * @return 
    *  possible object is 
    *  {@link String } 
    *  
    */ 
    public String getOrigPlatformNode() { 
     return origPlatformNode; 
    } 

    /** 
    * Sets the value of the origPlatformNode property. 
    * 
    * @param value 
    *  allowed object is 
    *  {@link String } 
    *  
    */ 
    public void setOrigPlatformNode(String value) { 
     this.origPlatformNode = value; 
    } 

    /** 
    * Gets the value of the eventID property. 
    * 
    * @return 
    *  possible object is 
    *  {@link String } 
    *  
    */ 
    public String getEventID() { 
     return eventID; 
    } 

    /** 
    * Sets the value of the eventID property. 
    * 
    * @param value 
    *  allowed object is 
    *  {@link String } 
    *  
    */ 
    public void setEventID(String value) { 
     this.eventID = value; 
    } 

    /** 
    * Gets the value of the parameter property. 
    * 
    * <p> 
    * This accessor method returns a reference to the live list, 
    * not a snapshot. Therefore any modification you make to the 
    * returned list will be present inside the JAXB object. 
    * This is why there is not a <CODE>set</CODE> method for the parameter property. 
    * 
    * <p> 
    * For example, to add a new item, do as follows: 
    * <pre> 
    * getParameter().add(newItem); 
    * </pre> 
    * 
    * 
    * <p> 
    * Objects of the following type(s) are allowed in the list 
    * {@link TParameter } 
    * 
    * 
    */ 
    public TParameter[] getParameter() { 
     return parameter; 
    } 
} 

TParameter.java

@XmlAccessorType(XmlAccessType.FIELD) 
@XmlType(name = "tParameter", propOrder = { 
    "parameterType", 
    "parameterValue" 
}) 
public class TParameter { 

    @XmlElement(name = "ParameterType") 
    protected int parameterType; 
    @XmlElement(name = "ParameterValue") 
    protected String parameterValue; 

    /** 
    * Gets the value of the parameterType property. 
    * 
    */ 
    public int getParameterType() { 
     return parameterType; 
    } 

    /** 
    * Sets the value of the parameterType property. 
    * 
    */ 
    public void setParameterType(int value) { 
     this.parameterType = value; 
    } 

    /** 
    * Gets the value of the parameterValue property. 
    * 
    * @return 
    *  possible object is 
    *  {@link String } 
    *  
    */ 
    public String getParameterValue() { 
     return parameterValue; 
    } 

    /** 
    * Sets the value of the parameterValue property. 
    * 
    * @param value 
    *  allowed object is 
    *  {@link String } 
    *  
    */ 
    public void setParameterValue(String value) { 
     this.parameterValue = value; 
    } 

} 

我曾嘗試不同陣列結構,List<TParameter>看看這是否會擺脫<item>標籤。似乎沒有任何工作。

如果有人能指示我獲得正確的定義,以便生成完全相同的請求格式,將不勝感激。 在此先感謝。

回答

0

如果您使用eclipse並使用new-> web service-> web service工具自動生成WSDL的Java代碼,那麼在生成java代碼之前,請轉至eclipse菜單window-> preferences-> axis emitter- >勾選名爲「將包裝的XML數組類型的直接數組構建到直接數組」的複選框