Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

 

This example will lead you through creating your first service with doing "code first" development with JAX-WS.

...

Alternatively you can use the following code. This gives you more control over the behaviour. For example you can add a logging interceptor:

 

...

Code Block
languagejava
titleServerFactoryBean
HelloWorldImpl implementor = new HelloWorldImpl(); 
JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean(); 
svrFactory.setServiceClass(HelloWorld.class); 
svrFactory.setAddress("http://localhost:9000/helloWorld"); 
svrFactory.setServiceBean(implementor); 
svrFactory.

...

create();

You could leave out the ServiceClass. But it is better to use it so the server and the client are created from the same interface. If you instead only use the implementation class subtle problems may occur.

...

For the client there is also the alternative approach that gives you more flexibility. Of course like above the logging interceptors are optional but they help a lot when starting::

 

 

JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); factory.getInInterceptors().add(new LoggingInInterceptor()); factory.getOutInterceptors().add(new LoggingOutInterceptor()); factory.setServiceClass(HelloWorld.class); factory.setAddress("http://localhost:9000/helloWorld"); HelloWorld client = (HelloWorld) factory.create(); String reply = client.sayHi("HI"); System.out.println("Server said: " + reply); System.exit(0);