我有带有以下WSDL的CXF服务:
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="PropertySetterImplService" targetNamespace="http://eshopCXFService/" xmlns="http://eshopCXFService/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://eshopCXFService/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsdl:types>
<schema xmlns="http://www.w3.org/2001/XMLSchema">
<import namespace="http://eshopCXFService/" schemaLocation="propertysetterimpl_schema1.xsd"/>
</schema>
<xsd:schema elementFormDefault="qualified" targetNamespace="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<xsd:element name="Security">
<xsd:complexType>
<xsd:sequence>
<xsd:element minOccurs="1" maxOccurs="1" name="UsernameToken">
<xsd:complexType>
<xsd:sequence>
<xsd:element minOccurs="1" maxOccurs="1" name="Username" type="xsd:string"/>
<xsd:element minOccurs="1" maxOccurs="1" name="Password">
<xsd:complexType>
<xsd:simpleContent>
<xsd:extension base="xsd:string">
<xsd:attribute name="Type" type="xsd:string" default="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText" />
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>
<wsdl:message name="securityHeader">
<wsdl:part name="security" element="wsse:Security">
</wsdl:part>
</wsdl:message>
<wsdl:message name="publishNewDescription">
<wsdl:part name="parameters" element="tns:publishNewDescription">
</wsdl:part>
</wsdl:message>
<wsdl:message name="publishNewImageURLResponse">
<wsdl:part name="parameters" element="tns:publishNewImageURLResponse">
</wsdl:part>
</wsdl:message>
<wsdl:message name="publishNewPriceResponse">
<wsdl:part name="parameters" element="tns:publishNewPriceResponse">
</wsdl:part>
</wsdl:message>
<wsdl:message name="publishNewDescriptionResponse">
<wsdl:part name="parameters" element="tns:publishNewDescriptionResponse">
</wsdl:part>
</wsdl:message>
<wsdl:message name="publishNewImageURL">
<wsdl:part name="parameters" element="tns:publishNewImageURL">
</wsdl:part>
</wsdl:message>
<wsdl:message name="publishNewPrice">
<wsdl:part name="parameters" element="tns:publishNewPrice">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="PropertySetter">
<wsdl:operation name="publishNewDescription">
<wsdl:input name="publishNewDescription" message="tns:publishNewDescription">
</wsdl:input>
<wsdl:output name="publishNewDescriptionResponse" message="tns:publishNewDescriptionResponse">
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="publishNewImageURL">
<wsdl:input name="publishNewImageURL" message="tns:publishNewImageURL">
</wsdl:input>
<wsdl:output name="publishNewImageURLResponse" message="tns:publishNewImageURLResponse">
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="publishNewPrice">
<wsdl:input name="publishNewPrice" message="tns:publishNewPrice">
</wsdl:input>
<wsdl:output name="publishNewPriceResponse" message="tns:publishNewPriceResponse">
</wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="PropertySetterImplServiceSoapBinding" type="tns:PropertySetter">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="publishNewDescription">
<wsdl:input>
<soap:header message="tns:securityHeader" part="security" use="literal"/>
</wsdl:input>
</wsdl:operation>
<wsdl:operation name="publishNewImageURL">
<wsdl:input>
<soap:header message="tns:securityHeader" part="security" use="literal"/>
</wsdl:input>
</wsdl:operation>
<wsdl:operation name="publishNewPrice">
<wsdl:input>
<soap:header message="tns:securityHeader" part="security" use="literal"/>
</wsdl:input>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="PropertySetterImplService">
<wsdl:port name="PropertySetterImplPort" binding="tns:PropertySetterImplServiceSoapBinding">
<soap:address location="http://localhost:8080/eshopCXFService/services"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
现在,我正尝试在Java 8的Eclipse中使用CXF生成Web服务客户端。然而,我得到的不是生成的代码,而是一个错误:
WSDLToJava Error: WSI-BP-1.0 R2209 violation: Unbound PortType elements in Operation 'publishNewDescription'
org.apache.cxf.tools.common.ToolException: WSI-BP-1.0 R2209 violation: Unbound PortType elements in Operation 'publishNewDescription'
at org.apache.cxf.tools.validator.internal.WSDL11Validator.isValid(WSDL11Validator.java:140)
at org.apache.cxf.tools.wsdlto.frontend.jaxws.wsdl11.JAXWSDefinitionBuilder.validate(JAXWSDefinitionBuilder.java:207)
at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.processWsdl(WSDLToJavaContainer.java:193)
at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.execute(WSDLToJavaContainer.java:156)
at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.execute(WSDLToJavaContainer.java:402)
at org.apache.cxf.tools.common.toolspec.ToolRunner.runTool(ToolRunner.java:105)
at org.apache.cxf.tools.wsdlto.WSDLToJava.run(WSDLToJava.java:113)
at org.apache.cxf.tools.wsdlto.WSDLToJava.run(WSDLToJava.java:86)
at org.apache.cxf.tools.wsdlto.WSDLToJava.main(WSDLToJava.java:185)
有人知道出了什么问题吗?我能够使用SoapUI(通过WSDL(毫无问题地连接和使用该服务。如果需要,很乐意发送更多信息。
根据错误消息,我假设您拥有的web服务不完全符合WSI。看见http://www.ws-i.org/Profiles/BasicProfile-1.0-2004-04-16.html,规则R2209:
描述中的wsdl:binding应该绑定wsdl:portType中wsdl:message的每个wsdl:part,它指的是soapbind:body、soapbind:header、soapbond:fault或soapbind:headerault中的一个。
web服务运行,您可以使用任何可以向其发送预期SOAP消息的客户端来调用它,只是该服务不尊重互操作性规范。
我已经有一段时间没有对WSDL进行互操作性故障排除了,但我认为您需要在<wsdl:operation>
s中的<wsdl:input>
和<wsdl:output>
中添加<soap:body use="literal"/>
。
如果你不控制web服务,那么这就不是你能做的。你可以尝试在不带-validate
标志的情况下运行WSDLToJava
,看看它是否生成代码。