JAX-WS vs SAAJ Style, Which to Use
Asked Answered
D

2

13

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?

Deb answered 7/10, 2010 at 19:27 Comment(0)
T
4

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."

Tiberius answered 29/4, 2014 at 11:36 Comment(0)
A
1

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.

Avra answered 7/10, 2010 at 20:49 Comment(1)
You mean; saaj is lower level which means you can be more spesific but you have to write a lot of things but JAXWS is more simple but you cannot be more spesific? Did I get you correctly?Belier

© 2022 - 2024 — McMap. All rights reserved.