JAX-WS vs SAAJ样式,使用哪种 [英] JAX-WS vs SAAJ Style, Which to Use

查看:125
本文介绍了JAX-WS vs SAAJ样式,使用哪种的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Service和Dispatch类与SOAPConnection类从Java代码调用Web服务之间有什么区别(哲学或其他)?

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

例如,类似于这个:

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

与这些行大致相似?

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?

推荐答案

以下行摘自Java SOA Cookbook - O'Reilly

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

The SOAP连接允许您在
a URL的末尾将SOAP消息发送到资源。这在任何情况下都很方便使用,但是如果该服务没有
有定义的WSDL则是必需的。这是因为调用Service.create需要传入WSDL的
位置。你可能很少有一个带有基于SOAP的
服务的WSDL,但它确实发生了,你会做好准备。

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

要创建与不公开WSDL的Web服务的连接,可以使用
SOAPConnection类直接与远程资源通信。然后创建一个表示要调用的远程
资源(servlet)的URL对象。传递SOAP请求消息和端点
哟你想调用你的连接对象上的call方法,然后等待
它返回一个SOAP响应。

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.

•传递给你的端点URL connection.call方法可以是字符串,也可以是
a java.net.URL。

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

这篇关于JAX-WS vs SAAJ样式,使用哪种的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆