我遇到了一个问题,几天后寻找答案后,我决定最好寻求在线帮助。
所以我有一个无法修改的客户端的WSDL。我在这里放了一个等效的版本:
<?xml version="1.0" encoding="UTF-8"?>
<definitions
xmlns:tns="http://apache.org/handlers"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:x1="http://apache.org/handlers/types"
name="WsdlInvestigation"
targetNamespace="http://apache.org/handlers">
<types>
<xsd:schema
xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://apache.org/handlers/types"
elementFormDefault="qualified">
<complexType name="getSomeDataParam">
<sequence>
<element name="inputParam" type="xsd:string" minOccurs="1" maxOccurs="unbounded"/>
</sequence>
</complexType>
<complexType name="getSomeDataResponse">
<sequence>
<element name="return" type="xsd:int"/>
</sequence>
</complexType>
<complexType name="FaultDetail">
<sequence>
<element name="faultInfo" type="xsd:string"/>
<element name="message" type="xsd:string"/>
</sequence>
</complexType>
</xsd:schema>
</types>
<message name="getSomeDataRequest">
<part name="parameters" type="x1:getSomeDataParamType"/>
</message>
<message name="getSomeDataResponse">
<part name="result" type="x1:getSomeDataResponseType"/>
</message>
<message name="wsdlInvestigationFault">
<part name="faultDetail" type="x1:FaultDetailType" />
</message>
<portType name="WsdlInvestigationPortType">
<operation name="getSomeData">
<input message="tns:getSomeDataRequest"/>
<output message="tns:getSomeDataResponse"/>
<fault name="wsdlInvestigationFault" message="tns:wsdlInvestigationFault"/>
</operation>
</portType>
<binding name="WsdlInvestigationBinding" type="tns:WsdlInvestigationPortType">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="getSomeData">
<soap:operation soapAction="getSomeData"/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
<fault name="wsdlInvestigationFault">
<soap:fault name="wsdlInvestigationFault" use="literal"/>
</fault>
</operation>
</binding>
<service name="WsdlInvestigationService">
<port name="WsdlInvestigationPort" binding="tns:WsdlInvestigationBinding">
<soap:address location="http://localhost:9000/handlers/WsdlInvestigationService/WsdlInvestigationPort"/>
</port>
</service>
</definitions>
当我将WSDL放入SoapUi时,可以创建如下请求:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:typ="http://apache.org/handlers/types">
<soapenv:Header/>
<soapenv:Body>
<parameters>
<!--1 or more repetitions:-->
<typ:inputParam>?</typ:inputParam>
</parameters>
</soapenv:Body>
</soapenv:Envelope>
我正在使用maven cxf-codegen-plugin插件生成源。 这是我的pom.xml的一部分
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${cxf.version}</version>
<executions>
<execution>
<id>generate-SOAPService1</id>
<phase>generate-sources</phase>
<configuration>
<wsdlOptions>
<wsdlOption>
<wsdl>${wsdl.file}</wsdl>
<bareMethods/>
<extraargs>
<!-- Add "toString" to objects -->
<extraarg>-xjc-Xts</extraarg>
</extraargs>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.9.1</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-xjc-ts</artifactId>
<version>2.2.12</version>
</dependency>
</dependencies>
</plugin>
生成的服务就是这样:
@WebService(targetNamespace = "http://apache.org/handlers", name = "WsdlInvestigationPortType")
@XmlSeeAlso({org.apache.handlers.types.ObjectFactory.class})
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
public interface WsdlInvestigationPortType {
@WebMethod(action = "getSomeData")
@WebResult(name = "result", targetNamespace = "", partName = "result")
public org.apache.handlers.types.GetSomeDataResponseType getSomeData(
@WebParam(partName = "parameters", name = "parameters", targetNamespace = "")
org.apache.handlers.types.GetSomeDataParamType paramPackage
) throws WsdlInvestigationFault;
}
我们可以看到,“ getSomeData”方法使用的是参数“ GetSomeDataParamType”。
如果进入GetSomeDataParamType类,我们将看不到带有@XmlRootElement注释的类,因此我无法用jaxb编组“ request”对象并最终出现异常。
问题是我无法修改WSDL。
我该怎么做才能生成正确的服务方法和可以编组的正确类?
我尝试用Jaxb进行调优,但没有成功。
预先感谢您的支持