将 Apache SOAP Web Service 迁移到基于 Java EE 标准的 JAX-RPC Web Service
可以将使用 Apache SOAP 开发的 Web Service 迁移到根据 Web Services for Java™ Platform, Enterprise Edition (Java EE) 规范开发的 Java API for XML-based RPC (JAX-RPC) Web Service。
开始之前
如果您已使用基于 Apache SOAP 的 Web Service,但现在想要开发和实现基于 Java 的 Web Service,那么需要迁移使用所有 4.0 版本及 5.0.2 之前的所有 5.0 版本来开发的客户机应用程序。
关于此任务
已除去基于 Apache SOAP 实现的 SOAP 安全性(XML 数字签名)。将应用程序迁移到 Web Service 的 JSR-109 实现并进行重新配置,而不是使用 SOAP-Security。
要根据 Java 标准迁移这些客户机应用程序:
过程
- 计划您的迁移策略。 可以使用两种方法中的一种将 Apache SOAP 客户机移植到 JAX-RPC Web Service 客户机:
- 如果您具有服务的 Web 服务描述语言 (WSDL) 文档或者可以创建服务的 WSDL 文档,请考虑使用 WSDL2Java 命令工具来生成 Web Service 的绑定。将 Apache SOAP 客户机改变为使用已生成的 JAX-RPC 绑定需要进行很多工作,但产生的客户机代码更可靠,并且更易于维护。
要遵循此方法,请参阅信息中心中有关开发 Web Service 客户机的文章。
- 如果您没有服务的 WSDL 文档,不想更改服务,并且要用最小的工作量移植 Apache SOAP 客户机,您可以将代码转换为使用类似于 Apache SOAP API 的 JAX-RPC 动态调用接口 (DII)。DII API 不使用 WSDL 或已生成的绑定。
- 如果您具有服务的 Web 服务描述语言 (WSDL) 文档或者可以创建服务的 WSDL 文档,请考虑使用 WSDL2Java 命令工具来生成 Web Service 的绑定。将 Apache SOAP 客户机改变为使用已生成的 JAX-RPC 绑定需要进行很多工作,但产生的客户机代码更可靠,并且更易于维护。
- 查看 GetQuote 样本。 可以在信息中心的“样本”部分中找到 Web Service 迁移样本。此样本位于 GetQuote.java 文件中,最初是为 Apache SOAP 用户编写且包含有关迁移到 JAX-RPC DII 接口所需的更改说明。要了解更多信息,请参阅信息中心中的“样本”部分。
- 将客户机应用程序从 Apache SOAP 转换到 JAX-RPC DII Apache SOAP API 和 JAX-RPC DII API 的结构类似。您可以在它们中实例化和配置 Call 对象、设置参数、调用操作和处理结果。 您可以在 JAX-RPC 中,使用下列命令创建 Service 对象的一般实例:
in JAX-RPC.javax.xml.rpc.Service service = ServiceFactory.newInstance().createService(new QName(""));
- Create the Call object. An instance of the
Call object is created with the following code:
in Apache SOAP.org.apache.soap.rpc.Call call = new org.apache.soap.rpc.Call ()
An instance of the Call object is created by
in JAX-RPC.java.xml.rpc.Call call = service.createCall();
- Set the endpoint Uniform Resource Identifiers (URI). The target URI for the operation is passed as a parameter to
in Apache SOAP.call.invoke: call.invoke("http://...", "");
The setTargetEndpointAddress method is used as a parameter to
in JAX-RPC.call.setTargetEndpointAddress("http://...");
Apache SOAP has a setTargetObjectURI method on the Call object that contains routing information for the request. JAX-RPC has no equivalent method. The information in the targetObjectURI is included in the targetEndpoint URI for JAX-RPC.
- Set the operation name. The operation name
is configured on the Call object by
。call.setMethodName("opName");
在 JAX-RPC 中使用 setOperationName 方法,其接受 QName 而不是 String 参数,如下面示例中的描述:call.setOperationName(new javax.xml.namespace.Qname("namespace", "opName"));
- Set the encoding style. The encoding style
is configured on the Call object by
in Apache SOAP.call.setEncodingStyleURI(org.apache.soap.Constants.NS_URI_SOAP_ENC);
The encoding style is set by a property of the Call object
。call.setProperty(javax.xml.rpc.Call.ENCODINGSTYLE_URI_PROPERTY, "http://schemas. xmlsoap.org/soap/encoding/");
- 声明参数和设置参数值。 Apache SOAP 参数类型和值由参数实例描述,在调用前,将它们收集到向量中并且在 Call 对象上设置,例如:
Vector params = new Vector (); params.addElement (new org.apache.soap.rpc.Parameter(name, type, value, encodingURI)); // repeat for additional parameters... call.setParams (params);
对于 JAX-RPC,用参数名和类型(不需要提供它们的值)配置 Call 对象,例如:
其中:call.addParameter(name, xmlType, mode); // repeat for additional parameters call.setReturnType(type);
- name (type java.lang.String) 是参数的名称
- xmlType (type javax.xml.namespace.QName) 是参数的 XML 类型
- mode (type javax.xml.rpc.ParameterMode) 是参数的方式,例如:IN、OUT 或 INOUT
- 进行调用。 已通过 Apache SOAP 中的
in Apache SOAP.org.apache.soap.Response resp = call.invoke(endpointURI, "");
The parameter values are collected into an array and passed to call.invoke as illustrated in the following example:
in JAX-RPC.Object resp = call.invoke(new Object[] {parm1, parm2,...});
- Check for faults. You can check for a SOAP
fault on the invocation by checking the response:
。if resp.generatedFault then { org.apache.soap.Fault f = resp.getFault; f.getFaultCode(); f.getFaultString(); }
如果调用时发生 SOAP 故障,那么 JAX-RPC 中显示 java.rmi.RemoteException 错误。try { ... call.invoke(...) } catch (java.rmi.RemoteException) ...
- 检索结果。 在 Apache SOAP 中,如果调用成功并返回结果,那么可以从 Response 对象获取此结果:
Parameter result = resp.getReturnValue(); return result.getValue();
In JAX-RPC, the result of invoke is the returned object when no exception is displayed:Object result = call.invoke(...); ... return result;
- Create the Call object. An instance of the
Call object is created with the following code:
结果
下一步做什么
根据 Web Services for Java EE 规范开发 Web Service 客户机。
测试已启用 Web Service 的客户机以确保迁移过程是成功的,并确保您可以在 Java EE 环境中实现这些 Web Service。


http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=twbs_migratewbs
文件名:twbs_migratewbs.html