This documentation is for WSO2 Application Server 5.2.1. View documentation for the latest release.
Build and Invoke a Service Using a WSDL - Application Server 5.2.1 - WSO2 Documentation
Skip to end of metadata
Go to start of metadata

This sample demonstrates how to build and call a Web service using a given WSDL file. This approach is also called contract-first.

  This Sample mainly addresses SOAP over HTTP in Document/Literal or Document/Literal wrapped style. For other transports or styles the configuration may look different.  

This sample consists of three sections as follows:

Code generation

Code generation in Maven is done using the cxf-codegen-plugin. For infomation, refer to Code generation is activated using a binding.xml file. In this case, the normal java Date is used for xsd:date and xsd:DateTime. If this is not present, the XMLGregorianCalendar will be used.

Another common use of the binding file is to generate asynchronous stubs. The line jaxws:enableAsyncMapping has to be uncommented to use this. More information about the binding file can be found here:

Service implementation

The service is implemented in the class CustomerServiceImpl, which simply implements the previously-generated service interface. The method getCustomersByName demonstrates how a query function looks like. The idea is to search and return all customers with the given name. If the searched name is null, the method returns an exception to indicate that no matching customer was found. (In a real implementation, a list of zero objects can typically be used). For any other name, the method returns a list of two customer objects. The number of  objects can be increased to test how fast CXF works for larger data.

Client implementation

The main client code lives in the class CustomerServiceTester, which needs a proxy to the service and demonstrates some calls and their expected outcome using junit assertions.

The first call is a request getCustomersByName for all customers with name "Smith" and the result is checked. Then, the same method is called with the invalid name "None". In this case a NoSuchCustomerException is expected. The third call shows that the one way method updateCustomer will return instantly even if the service needs some time to process the request.

The classes CustomerServiceClient and CustomerServiceSpringClient show how to get a service proxy using JAX-WS and how to wire it to your business class (in this case, CustomerServiceTester).

Building and running the sample

This sample can be found at <AS_HOME>\samples\Jaxws-Jaxrs\wsdl_first_jaxws

For information on building and running the sample, see Building and Running JAX-WS Samples.

  1. If you have a EPR location other than http://localhost:9763/java_first_jaxws/services/hello_world, edit the run-client script.
  2. Prior to running the client, it is recommended to confirm that the generated WSDL (http://{ip}:{port}/java_first_jaxws/services/hello_world?wsdl) can be seen from a web browser.

  • No labels