使用 java 6、CXF 2.3.1 和 Maven 2。
当通过 Maven 插件运行 CXF wsdl2java 工具时,我遇到了 以下问题:
wsdl2java -d C:\devel\adpoint_callback\target\generated-sources\cxf -impl -validate -verbose file:/C:/devel/adpoint_callback/src/main/resources/wsdl/foobar.wsdl wsdl2java - Apache CXF 2.3.1
WSIBP Validator found <binding> is NOT a SOAP binding [DEBUG]
org.apache.cxf.tools.common.ToolException: org.apache.cxf.wsdl11.WSDLRuntimeException: BINDING_MISSING_TYPE at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.execute(WSDLToJavaContainer.java:279)
... ~20 rows
Caused by: org.apache.cxf.wsdl11.WSDLRuntimeException: BINDING_MISSING_TYPE at org.apache.cxf.wsdl11.WSDLServiceBuilder.buildServices(WSDLServiceBuilder.java:306) at org.apache.cxf.wsdl11.WSDLServiceBuilder.buildServices(WSDLServiceBuilder.java:181)
使用以下改编自 http://www.w3schools.com/WSDL/wsdl_binding.asp 的最小 WSDL 文件:
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="notification"
targetNamespace="http://example.com/mynamespace"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsd="http://example.com/mynamespace/xsd" >
<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsd="http://example.com/mynamespace/xsd"
targetNamespace="http://example.com/mynamespace/xsd" >
<xs:element name="RequestType" type="xsd:content"/>
<xs:element name="ResponseType" type="xsd:content"/>
<xs:complexType name="content">
<xs:sequence>
<xs:element name="text" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="getTermRequest">
<wsdl:part name="body" element="xsd:RequestType"/>
</wsdl:message>
<wsdl:message name="getTermResponse">
<wsdl:part name="body" element="xsd:ResponseType"/>
</wsdl:message>
<wsdl:portType name="glossaryTerms">
<wsdl:operation name="getTerm">
<wsdl:input message="getTermRequest"/>
<wsdl:output message="getTermResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="binding" type="glossaryTerms">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="getTerm">
<soap:operation soapAction="http://example.com/getTerm" />
<wsdl:input><soap:body use="literal"/></wsdl:input>
<wsdl:output><soap:body use="literal"/></wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="testService" >
<wsdl:port name="testPort" binding="binding">
<soap:address location="http://example.com/mynamespace"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
服务/绑定(bind)用法与 WSDL 1.1 规范文档中示例中使用的完全相同 http://www.w3.org/TR/wsdl
如果没有 -validate 标志,代码生成也不会工作 - 验证警告不会显示。
当然,问题是为什么
[编辑:修复]
如果我将默认命名空间设置为与我的 targetNamespace 相同的值,错误就会消失。 CXF 能够以某种方式处理我没有设置默认 namespace 这一事实,直到它应该处理绑定(bind)的那一刻。那时它会抛出一个关于缺少绑定(bind)类型的误导性异常。
因此,解决这个问题就像更改 wsdl:definition 标记的属性一样简单 定义默认命名空间:
<wsdl:definitions name="notification"
targetNamespace="http://example.com/mynamespace"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsd="http://example.com/mynamespace/xsd"
xmlns="http://example.com/mynamespace" >
最佳答案
当您使用 targetNamespace="http://example.com/mynamespace"
并像这样定义你的绑定(bind):
<wsdl:binding name="binding" type="glossaryTerms">
...
</wsdl:binding>
然后您必须在 wsdl:service
中引用该绑定(bind)具有相应命名空间的部分。具体应该是:binding="<namespace>:<binding_name>"
.这意味着您必须定义与目标命名空间相同的命名空间。例如命名空间tns:
<wsdl:definitions name="notification"
targetNamespace="http://example.com/mynamespace"
...
xmlns:tns="http://example.com/mynamespace">
然后,在 wsdl:service
中引用它时部分:
<wsdl:service name="testService">
<wsdl:port name="testPort" binding="tns:binding">
<soap:address location="http://example.com/mynamespace"/>
</wsdl:port>
</wsdl:service>
关于java - CXF wsdl2java 导致 BINDING_MISSING_TYPE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6489608/