定制 Web Service 端点

可以使用 ibm-ws-bnd.xml 文件来定制应用程序中的服务器提供者和客户机的 Web Service 端点。

开始之前

ibm-ws-bnd.xml 文件必须位于基于 Web 的 Web Service 应用程序(WAR 文件)的 /WEB-INF 目录中,或基于 EJB 的 Web Service 应用程序(JAR 文件)的 /META-INF 目录中。如果客户机正在运行 clientContainer,那么 ibm-ws-bnd.xml 文件必须在客户机 EAR 的 JAR 文件的 /META-INF 目录中。

关于此任务

通过配置 ibm-ws-bnd.xml 文件,您可以覆盖服务提供者和使用者的 Web Service 地址配置,使用部署在 Liberty 上的应用程序中的特定 URL 来导出 Web Service,然后从 JAX-WS 客户机应用程序导入这些 Web Service。

对于您可以在 ibm-ws-bnd.xml 文件中配置的所有可用元素,请参阅 ibm-ws-bnd.xml 文件

过程

  1. 覆盖服务提供者的 Web Service 绑定。
    1. 覆盖 Web Service 端点地址。webservice-endpoint 元素中,您可以覆盖由 port-component-name 属性标识的 Web Service 端点的端点地址。address 属性指定应用程序的上下文根的相对路径。
      <?xml version="1.0" encoding="UTF-8"?>
      <webservices-bnd xmlns="http://websphere.ibm.com/xml/ns/javaee"
      				xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      				xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-ws-bnd_1_0.xsd"
      		version="1.0">
      	<!-- 0 to many endpoint descriptions -->
      	<webservice-endpoint port-component-name="Hello" address="/hiService" />
      </webservices-bnd>
    2. 覆盖基于 EJB 的 Web Service 的上下文根。 如果 Web Service 是基于 EJB 的 Web Service,并且是在 EJB 应用程序(JAR 归档)中进行定义,那么缺省上下文根为 EJB JAR 名称。但是,您可以使用 http-publishing 元素的 context-root 属性来覆盖缺省值。
      <?xml version="1.0" encoding="UTF-8"?>
      <webservices-bnd xmlns="http://websphere.ibm.com/xml/ns/javaee"
      				xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      				xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-ws-bnd_1_0.xsd"
      		version="1.0">
      	<!-- optional http publishing module overrides -->
      	<http-publishing context-root="/HiServer" />
      </webservices-bnd>
      注: 仅当 Web Service 是基于 EJB 的 Web Service,并且是在 EJB JAR 归档中进行定义时,context-root 属性才有效。如果 Web Service 是在 Web 应用程序(WAR 归档)中进行定义,那么无论它是否为基于 EJB 的 Web Service,都会忽略 http-publishing 元素的 context-root 属性,并且上下文根始终将为该 Web 应用程序的上下文根。
  2. 覆盖客户机应用程序的 Web Service 绑定。
    1. 覆盖 WSDL 文档所在的位置。service-ref 元素中,您可以覆盖 Web Service 客户机应用程序中的 Web Service 引用的 WSDL 位置。
      <?xml version="1.0" encoding="UTF-8"?>
      <webservices-bnd xmlns="http://websphere.ibm.com/xml/ns/javaee"
      				xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      				xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-ws-bnd_1_0.xsd"
      		version="1.0">
      	<service-ref name="services/hello" wsdl-location="http://localhost:9080/HiServer/hiService?wsdl" />
      </webservices-bnd>
      wsdl-location 属性指定绝对 URI(使用 HTTP 或文件协议),并且它还可以是指向该客户机应用程序的根目录的相对 URI。例如:
      <?xml version="1.0" encoding="UTF-8"?>
      <webservices-bnd xmlns="http://websphere.ibm.com/xml/ns/javaee" 
      				xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      				xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-ws-bnd_1_0.xsd"
      		version="1.0">
      	<service-ref name="services/hello" wsdl-location="WEB-INF/wsdl/hiService.wsdl" />
      </webservices-bnd>
    2. 覆盖端口地址。port 元素中,您可以覆盖 Web Service 客户机中的 Web Service 引用的端口地址。
      <?xml version="1.0" encoding="UTF-8"?>
      <webservices-bnd xmlns="http://websphere.ibm.com/xml/ns/javaee"
      				xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      				xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-ws-bnd_1_0.xsd"
      		version="1.0">
      	<service-ref name="services/hello" wsdl-location="WEB-INF/wsdl/hiService.wsdl">
      				<port name="HelloPort" namespace="http://server.ejb.hello.sample.jaxws.ws.ibm.com/" 
      				address="http://localhost:9080/HiServer/hiService" />
      	</service-ref>
      </webservices-bnd>
      port 元素的 address 属性指定 Web Service 端口的绝对 URI。如果所引用的 Web Service 只有一个端口,那么您可以使用 service-ref 元素的 port-address 属性。例如:
      <webservices-bnd xmlns="http://websphere.ibm.com/xml/ns/javaee"
      				xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      				xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-ws-bnd_1_0.xsd"
      		version="1.0">
      		<service-ref name="services/hello"
      			port-address="http://localhost:9080/HiServer/hiService" />
      </webservices-bnd>
      注: 如果同时指定了 service-ref 元素的 port-address 属性以及 port 元素的 address 属性,那么 port 元素的 address 属性生效。

用于指示主题类型的图标 任务主题

文件名:twlp_dep_jaxws_binding.html