JAX-WS 与 SAAJ 风格,使用哪一个
使用 Service 和 Dispatch 类从 Java 代码调用 Web 服务与 SOAPConnection 类之间有什么区别(哲学上或其他方面)?
例如,像这样的东西:
SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = scf.createConnection();
SOAPMessage reply = soapConnection.call(soapMessage, url);
vs 大致沿着这些思路的东西?
svc = Service.create(url, serviceName);
Dispatch<SOAPMessage> dispatch = svc.createDispatch(portName, SOAPMessage.class, service.Mode.MESSAGE);
SOAPMessage reply = (SOAPMessage)dispatch.invoke(soapMessage);
它们之间有什么区别,为什么选择一种方法而不是另一种?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下行摘自 Java SOA Cookbook - O'Reilly
“SOAP 连接允许您在末尾向资源发送 SOAP 消息
一个网址。这在任何情况下都很方便使用,但如果该服务不支持,则这是必要的
有一个定义的 WSDL。那是因为调用 Service.create 需要传入
WSDL 的位置。您可能很少有基于 SOAP 的 WSDL
服务,但它确实发生了,你会做好准备的。
要创建与不公开 WSDL 的 Web 服务的连接,您可以使用
SOAPConnection 类直接与远程资源进行通信。然后创建一个代表远程的 URL 对象
您要调用的资源(servlet)。传递 SOAP 请求消息和端点
您想要调用连接对象上的 call 方法,然后等待
它返回 SOAP 响应。
• 传递给connection.call 方法的端点URL 可以是字符串或
java.net.URL。”
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."
我有一种感觉,最后,调度只是将操作委托给 SAAJ 层。不过,我还无法证实这一点。
从更好的实践的角度来看,我觉得 Dispatch 方法更合适,因为它抽象了使用较低级别 SAAJConnection API 的一些开销。就像 - 不需要对连接实例执行 close() 操作,与 SOAPConnection 实例不同,不需要重新创建调度引用。
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.