Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JAX-WS vs SAAJ Style, Which to Use

What is difference, philosophical or otherwise, between calling a web service from Java code using Service and Dispatch classes, vs a SOAPConnection class?

For example, something like this:

SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = scf.createConnection();
SOAPMessage reply = soapConnection.call(soapMessage, url);

vs something roughly along these lines?

svc = Service.create(url, serviceName);
Dispatch<SOAPMessage> dispatch = svc.createDispatch(portName, SOAPMessage.class, service.Mode.MESSAGE);
SOAPMessage reply = (SOAPMessage)dispatch.invoke(soapMessage);

What is the difference between these, and why select one approach over the other?

like image 813
user186668 Avatar asked Oct 07 '10 19:10

user186668


2 Answers

The following line are excerpt from Java SOA Cookbook - O'Reilly

"The SOAP connection allows you to send a SOAP message to a resource at the end of a URL. This is convenient to use in any situation, but necessary if that service does not have a defined WSDL. That’s because calling Service.create requires passing in the location of the WSDL. It may be rare that you don’t have a WSDL with a SOAP-based service, but it does happen, and you’ll be prepared.

To create a connection to a web service that does not expose a WSDL, you can use the SOAPConnection class to communicate directly with the remote resource. You then create a URL object representing the remote resource (servlet) you want to call. Pass the SOAP request message and the endpoint you want to invoke to the call method on your connection object, and then wait for it to return a SOAP response.

• The endpoint URL passed to the connection.call method can be either a string or a java.net.URL."

like image 69
Sameer Sarmah Avatar answered Sep 22 '22 06:09

Sameer Sarmah


I have a feeling that at the end, the Dispatch simply delegates the actions to a SAAJ layer. However, I haven't been able to confirm that.

From the perspective of what's a better practice, then i feel the Dispatch methodology is more appropriate since it abstracts away some of the overheads of working with the lower level SAAJConnection API. Like - there's no need to do a close() on the connection instance, the dispatch reference need not be re-created unlike the SOAPConnection instance.

like image 1
anirvan Avatar answered Sep 22 '22 06:09

anirvan