Main » 2011»March»30 » Consuming WebService using Jax-ws in Spring - Basic
5:54 PM
Consuming WebService using Jax-ws in Spring - Basic
Following on from my guide to Web service in Lotus Notes, I will now discuss the ins and outs of consuming them in java. Specfically Java spring and Jax-WS.
First off a few pre-cursors in this guide I will not explain wsdl in any great detail so for some background please read the excellent guides from w3c. Also the eclipse plugin "SoapUI” is amazingly useful for working with webservices.
The JAX-WS classes are bundled in with the springframework so no need to go find them.
Firstly lets set up a very basic consumer service.
In your applicationContext-servlet.xml you’ll need to set up your JAX-WS bean. As below.
As can be seen its very basic functionality. The wsdl url, default namespace, service and port names as specified in the wsdl. The only thing "java” is the definition of a service Interface.
The service interface is what it says on the tin. It is an interface in which we are telling java how to deal with the services methods.
The sample above shows the setup for simple calls to simple methods of the webservice.
· @WebService annotataion sets simple information about the service. · @SOAPBinding annotation sets the parameter style of the service. In simple methods such as those above where the most being passed in the soap message is a simple string. Than use Bare. · @WebMethod() annotation assigns the webservice method and url. · @WebParam() annotation specifies a parameter to be sent to the webservice.
So in this example we have a webservice called test. It has at least two methods (SAYHELLO and SAYMESSAGE). SAYHELLO is a very basic method that is called and returns a string. SAYMESSAGE accepts a single parameter and returns a single string.
Usage.
@Controller
@Configurable
public class TestController {
As you can see after the work to set it up the usage is simple. You may also notice we never set up a class for TestService, we don’t have to JAX-WS has done it for us.
Next up consuming complex webservices. Including creation of xml wrappers for soap messages. Exciting!!!
What happened to your follow up on comlex webservices? I'd like to see this approach for passing complex objects instead of strings. Such as a Person object with member variables like (date of birth, gender, first name etc).