无法生成 CXF 客户端 "Unbound PortType elements in Operation"

Cannot generate CXF client "Unbound PortType elements in Operation"

我有以下 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>

现在我正尝试在 Eclipse 中使用 CXF 和 Java8 生成 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:

A wsdl:binding in a DESCRIPTION SHOULD bind every wsdl:part of a wsdl:message in the wsdl:portType to which it refers to one of soapbind:body, soapbind:header, soapbind:fault or soapbind:headerfault.

Web 服务 运行s,您可以使用任何可以向其发送预期 SOAP 消息的客户端调用它,只是该服务不遵守 interoperability specifications.

自从我对 WSDL 的互操作性进行故障排除以来已经有一段时间了,但我认为您需要在 <wsdl:operation> 中向 <wsdl:input><wsdl:output> 添加 <soap:body use="literal"/>

如果您不控制 Web 服务,那么您将无能为力。您可以尝试在没有 -validate 标志的情况下 运行 WSDLToJava 来查看它是否生成代码。