端点引用是 Web Service 寻址 (WS-Addressing) 互操作性协议的主要概念,它们提供了用于封装有关特定 Web Service 端点的信息的标准机制。此产品提供了界面,让您可以使用标准的 JAX-WS API 来创建端点引用。
关于此任务
本任务是创建使用 Web Service 寻址的 JAX-WS Web Service 应用程序的子任务。
如果要编写使用标准 JAX-WS WS-Addressing API 的应用程序,请完成此任务。此类应用程序需要端点引用来确定目标 Web Service 端点。标准 JAX-WS API 设计为仅创建简单的端点引用,因此具有以下限制:
- 无法创建高度可用或工作负载管理的端点引用。
- 无法创建表示有状态会话 Bean 的端点引用。
- 无法将使用 JAX-WS API 创建的类与 IBM 专有 WS-Addressing SPI 一起使用。
通过使用 IBM 专有 WS-Addressing
API 来创建端点引用,然后将它们转换为可由应用程序的其余部分使用的标准 JAX-WS 端点引用可克服这些限制。
过程
- 如果端点需要创建代表其自身的端点引用,请使用 Web Service 上下文对象的 getEndpointReference 方法,传入代表要与端点引用相关联的引用参数的元素对象(如果不想指定任何引用参数,那么传入 null 对象)。
缺省情况下,此方法创建 W3CEndpointReference 对象。如果要创建 SubmissionEndpointReference 对象(代表符合 2004/08 WS-Addressing 规范的端点),请将端点引用类型作为参数传递。
例如,以下代码片段使用 getEndpointReference 方法来返回具有相关联凭单标识的 W3CEndpointRerence 对象:...
@WebService(name="Calculator",
targetNamespace="http://calculator.org")
public class Calculator {
@Resource
WebServiceContext wsc;
...
// Create the ticket id
element = document.createElementNS(
"http://calculator.jaxws.axis2.apache.org", "TicketId");
element.appendChild( document.createTextNode("123456789") );
...
public W3CEndpointReference getEPR() {
// Get the endpoint reference and associate the ticket id
// with it as a reference parameter
W3CEndpointReference epr = (W3CEndpointReference)wsc.getEndpointReference(element);
return epr;
}
...
以下代码行显示如何为前面的样本创建 2004/08 端点引用:SubmissionEndpointReference epr = (SubmissionEndpointReference)
wsc.getEndpointReference(SubmissionEndpointReference.class, element);
- 如果端点需要创建表示其他端点的端点引用,请根据您要使用的名称空间使用 W3CEndpointReferenceBuilder 类或 SubmissionEndpointReferenceBuilder 类。
- 创建相应构建器类的实例。 如果要创建符合 2005/08 WS-Addressing 规范的端点引用,请使用 W3CEndpointReferenceBuilder 类。如果要创建符合 2004/08
WS-Addressing 规范的端点引用,请使用 SubmissionEndpointReferenceBuilder 类。
- 根据端点位置设置构建器实例的以下一个或多个属性。
- 可选: 根据需要设置构建器实例的其他属性。 例如,如果 Web Service 用于访问资源实例,请使用 referenceParameter 属性将资源标识与端点引用相关联。有关您可以设置的属性的更多信息,请参阅 API 文档。
- 在构建器实例上调用 build 方法来获取端点引用。
例如,以下代码片段使用 W3CEndpointReferenceBuilder 类来获取符合 2005/08 规范的端点引用,并指向另一个应用程序中的端点:...
@WebService(name="Calculator", targetNamespace="http://calculator.org")
public class Calculator {
public W3CEndpointReference getEPR() {
...
// Create the builder object
W3CEndpointReferenceBuilder builder = new
W3CEndpointReferenceBuilder();
// Modify builder properties
builder.address(otherServiceURI);
// Create the endpoint reference from the builder object
W3CEndpointReference epr = builder.build();
return epr;
}
...
以下代码片段使用 SubmissionEndpointReferenceBuilder 类来获取符合 2004/08 规范的端点引用,并指向此应用程序中另一个模块内的端点:...
@WebService(name="Calculator", targetNamespace="http://calculator.org")
public class Calculator {
public W3CEndpointReference getEPR() {
...
// Create the builder object
SubmissionEndpointReferenceBuilder builder = new
SubmissionEndpointReferenceBuilder();
// Modify builder properties
builder.serviceName(calculatorService);
builder.endpointName(calculatorPort);
// Create the endpoint reference from the builder object
SubmissionEndpointReference epr = builder.build();
return epr;
}
...
下一步做什么
- 如果需要,请使用 createIBMEndpointReference 方法将端点引用转换为 com.ibm.websphere.wsaddressing.EndpointReference 类的实例。例如,在客户机上,您希望为出站消息设置 FaultTo 消息寻址属性。不能使用 JAX-WS API 设置此属性,所以必须将代表 FaultTo 端点的端点引用转换为 com.ibm.websphere.wsaddressing.EndpointReference 类的实例,然后再将其作为 BindingProvider 对象上的属性进行设置。
- 执行创建使用 Web Service 寻址的 JAX-WS Web Service 应用程序以继续。