Using java 6, CXF 2.3.1 and Maven 2.
When running CXF wsdl2java tool via the Maven plugin, I am encountering the following issue:
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)
Using the following minimal WSDL file adapted from http://www.w3schools.com/WSDL/wsdl_binding.asp :
<?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>
The service/binding usage is exactly as used in the example within the WSDL 1.1 specification document http://www.w3.org/TR/wsdl
The code generation will not work without the -validate flag either - The validation warnings just do not show up.
Question is - of course - why the <soap:binding> element is not accepted as a binding type for the binding element as it should.
[ EDIT : Fix ]
If I set the default namespace to the same value as my targetNamespace, the error disappears. Somehow the CXF is able to handle the fact that I do not set the default namespace up until the moment it was supposed to handle the binding. At that point it throws out a misleading excep开发者_运维技巧tion about missing binding type.
Therefore, fixing this is as easy as changing the attributes of the wsdl:definition tag to define the default namespace:
<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" >
When you use the targetNamespace="http://example.com/mynamespace"
and define your binding like that:
<wsdl:binding name="binding" type="glossaryTerms">
...
</wsdl:binding>
Then you have to refer to that binding in the wsdl:service
section with the corresponding namespace. Specifically, it should be: binding="<namespace>:<binding_name>"
. It means that you have to define the namespace identical to the targetNamespace. For example, the namespace tns:
<wsdl:definitions name="notification"
targetNamespace="http://example.com/mynamespace"
...
xmlns:tns="http://example.com/mynamespace">
And then, when referring to it in the wsdl:service
section:
<wsdl:service name="testService">
<wsdl:port name="testPort" binding="tns:binding">
<soap:address location="http://example.com/mynamespace"/>
</wsdl:port>
</wsdl:service>
精彩评论