Skip to main content

Generating the stub code from the WSDL contract

After defining the WSDL contract, you can generate client code using the CXF wsdl2java utility. Enter the following command at a command-line prompt:

wsdl2java -client -d ClientDir hello_world.wsdl

Where ClientDir 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 the above WSDL. The -client option generates starting point code for a client main() method.

The preceding wsdl2java 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 the wsdl2java command 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 port type. In JAX-WS terminology, this Java interface is a service endpoint interface.

    • SOAPService is a Java class 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.apache.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.

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – please let us know!