Once your code is annotated, you can generate a WSDL contract for your service using the java2ws
command's -wsdl
flag. For a detailed listing of options for the java2ws command see
java2ws in Web Service Tool Reference.
To call the WSDL generator from Ant use the java task to execute the
org.apache.cxf.tools.java2ws.JavaToWS
class and pass -wsdl
as one of its arguments.
Example 1.18 shows a sample Ant target that calls the WSDL generator.
Example 1.18. Calling the WSDL Generator from Ant
<project name="java2ws" basedir="."> <property name="fsf.home" location ="/usr/myapps/fsf-trunk"/> <property name="build.classes.dir" location ="${basedir}/build/classes"/> <path id="fsf.classpath"> <pathelement location="${build.classes.dir}"/> <fileset dir="${fsf.home}/lib"> <include name="*.jar"/> </fileset> </path> <target name="WSDLGen"> <java classname="org.apache.cxf.tools.java2ws.JavaToWS" fork="true"> <arg value="-wsdl"/> <arg value="service.Greeter"/> <classpath> <path refid="fsf.classpath"/> </classpath> </java> </target> </project>
![]() | Important |
---|---|
You must set the Java task's fork to true. |
Example 1.19 shows the WSDL contract that is generated for the SEI shown in Example 1.7.
Example 1.19. Generated WSDL from an SEI
<?xml version="1.0" encoding="UTF-8"?> <wsdl:definitions targetNamespace="http://demo.eric.org/" xmlns:tns="http://demo.eric.org/" xmlns:ns1="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns2="http://demo.eric.org/types" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"> <wsdl:types> <xsd:schema> <xs:complexType name="quote"> <xs:sequence> <xs:element name="ID" type="xs:string" minOccurs="0"/> <xs:element name="time" type="xs:string" minOccurs="0"/> <xs:element name="val" type="xs:float"/> </xs:sequence> </xs:complexType> </xsd:schema> </wsdl:types> <wsdl:message name="getStockQuote"> <wsdl:part name="stockTicker" type="xsd:string"> </wsdl:part> </wsdl:message> <wsdl:message name="getStockQuoteResponse"> <wsdl:part name="updatedQuote" type="tns:quote"> </wsdl:part> </wsdl:message> <wsdl:portType name="quoteReporter"> <wsdl:operation name="getStockQuote"> <wsdl:input name="getQuote" message="tns:getStockQuote"> </wsdl:input> <wsdl:output name="getQuoteResponse" message="tns:getStockQuoteResponse"> </wsdl:output> </wsdl:operation> </wsdl:portType> <wsdl:binding name="quoteReporterBinding" type="tns:quoteReporter"> <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" /> <wsdl:operation name="getStockQuote"> <soap:operation style="rpc" /> <wsdl:input name="getQuote"> <soap:body use="literal" /> </wsdl:input> <wsdl:output name="getQuoteResponse"> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="quoteReporterService"> <wsdl:port name="quoteReporterPort" binding="tns:quoteReporterBinding"> <soap:address location="http://localhost:9000/quoteReporterService" /> </wsdl:port> </wsdl:service> </wsdl:definitions>