我正在尝试将我们的java spring应用程序集成到客户端系统中。客户端系统需要调用我们的SOAP Web服务之一来提供数据。他们已经有一个系统,我们将替换它。客户尚未准备好对其进行任何更改,并要求我们以与现在相同的格式提供Web服务。当我们尝试使用Apache Axis 1生成WSDL时,它的给定和额外的<item>
标记并重复该标记而不是实际的数组参数
他们提供了现有的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>
上述wsdl的soap请求是
<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轴生成的wsdl如下
<?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>
如您所见,原始请求具有表示为
的重复数组(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 :(得分:0)
如果您正在使用eclipse并使用new-&gt; web service-&gt; web服务工具自动生成WSDL的Java代码,那么在生成java代码之前,请转到eclipse菜单窗口 - &gt; preferences-&gt;轴发射器 - >勾选名为“首选构建bean到包装XML数组类型的直数组”的复选框