You use wsdl2java to generate the stub code from the WSDL contract. The stub code provides the supporting code that is required to invoke operations on the remote service.
For consumers, wsdl2java can generate the following kinds of code:
Stub code — supporting files for implementing a consumer.
Starting point code — sample code that connects to the remote service and invokes every operation on the remote service.
Ant build file — a build.xml
file intended for use with the ant build utility. It has targets for building and for running the sample consumer.
You generate consumer code using wsdl2java. Enter the following command at a command-line prompt:
wsdl2java -ant -client -d outputDir
hello_world.wsdl
Where outputDir
is the location of a directory where you would like to put the generated files and hello_world.wsdl
is a file containing the contract shown in Example 3.1, “HelloWorld WSDL Contract”. The -ant
option generates an ant build.xml
file, for use with the ant build utility. The -client
option generates starting point code for the consumer's main()
method.
For a complete list of the arguments available for wsdl2java see wsdl2java in Celtix Enterprise Command Reference.
The preceding command generates the following Java packages:
org.apache.hello_world_soap_http
This package name is generated from the http://apache.org/hello_world_soap_http
target namespace. All of the WSDL entities defined in this target namespace (for example, the Greeter port type and the SOAPService service) map to Java classes in the corresponding Java package.
org.apache.hello_world_soap_http.types
This package name is generated from the http://apache.org/hello_world_soap_http/types
target namespace. All of the XML types defined in this target namespace (that is, everything defined in the wsdl:types
element of the HelloWorld contract) map to Java classes in the corresponding Java package.
The stub files generated by wsdl2java fall into the following categories:
Classes representing WSDL entities (in the org.apache.hello_world_soap_http package) — the following classes are generated to represent WSDL entities:
Greeter
is a Java interface that represents the Greeter wsdl:portType
element. In JAX-WS terminology, this Java interface is the service endpoint interface (SEI).
SOAPService
is a Java service class (extending javax.xml.ws.Service
) that represents the SOAPService wsdl:service
element.
PingMeFault
is a Java exception class (extending java.lang.Exception
) that represents the pingMeFault wsdl:fault
element.
Classes representing XML types (in the org.objectweb.hello_world_soap_http.types package) — in the HelloWorld example, the only generated types are the various wrappers for the request and reply messages. Some of these data types are useful for the asynchronous invocation model.