自訂 Web 服務端點
您可以利用 ibm-ws-bnd.xml 檔來自訂應用程式內伺服器提供者和用戶端的 Web 服務端點。
開始之前
ibm-ws-bnd.xml 檔必須在 Web 型 Web 服務應用程式(WAR 檔)的 /WEB-INF 目錄中,或在 EJB 型 Web 服務應用程式(JAR 檔)的 /META-INF 目錄中。 如果用戶端是在 clientContainer 中執行,ibm-ws-bnd.xml 檔必須位於用戶端 EAR 中之 JAR 檔的 /META-INF 目錄內。
關於這項作業
透過配置 ibm-ws-bnd.xml 檔,您可以置換服務提供者和消費者兩者的 Web 服務位址配置、利用部署於 Liberty 的應用程式中的特定 URL 來匯出您的 Web 服務,以及從 JAX-WS 用戶端應用程式匯入 Web 服務。
關於 ibm-ws-bnd.xml 檔內所能配置的所有可用元素,請參閱Liberty:ibm-ws-bnd.xml 檔。
程序
- 置換服務提供者的 Web 服務連結。
- 置換 Web 服務端點位址。 在 webservice-endpoint 元素中,您可以置換 port-component-name 屬性所識別之 Web 服務端點的端點位址。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>
- 置換 EJB 型 Web 服務的環境定義根目錄。 如果 Web 服務是一個 EJB 型 Web 服務,且定義在 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 服務是一個 EJB 型 Web 服務,且定義在 EJB JAR 保存檔中時,context-root 屬性才有效。如果 Web 服務定義在 Web 應用程式(WAR 保存檔)中,不論它是否為 EJB 型 Web 服務,系統都不會處理 http-publishing 元素的 context-root 屬性,環境定義根目錄將一律是 Web 應用程式的環境定義根目錄。
- 置換 Web 服務端點位址。 在 webservice-endpoint 元素中,您可以置換 port-component-name 屬性所識別之 Web 服務端點的端點位址。address 屬性指定應用程式環境定義根目錄的相對路徑。
- 置換用戶端應用程式的 Web 服務連結。
- 置換 WSDL 文件的位置。 在 service-ref 元素中,您可以置換 Web 服務參照在 Web 服務用戶端應用程式內的 WSDL 位置。
wsdl-location 屬性會指定絕對 URI(可以是 HTTP 或 file 通訊協定),也可以是用戶端應用程式根目錄的相對 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="http://localhost:9080/HiServer/hiService?wsdl" /> </webservices-bnd>
<?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>
- 置換埠位址。 在 port 元素中,您可以在 Web 服務用戶端中置換 Web 服務參照內的埠位址。
port 元素的 address 屬性指定 Web 服務埠的絕對 URI。如果參照的 Web 服務只有一個埠,您可以使用 service-ref 元素的 port-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"> <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>
<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 屬性會生效。
- 置換 WSDL 文件的位置。 在 service-ref 元素中,您可以置換 Web 服務參照在 Web 服務用戶端應用程式內的 WSDL 位置。

檔名:twlp_dep_jaxws_binding.html