Implementing web services applications with JAX-WS

When starting from existing JavaBeans or enterprise beans, you can use a bottom-up approach to developing Web services based on the Java™ API for XML-Based Web Services (JAX-WS) programming model.

Before you begin

Determine the existing JavaBeans or enterprise beans that you want to expose as a JAX-WS web service.

最佳作法 最佳作法: IBM® WebSphere® Application Server 支援 Java API for XML 型 Web 服務 (JAX-WS) 程式設計模型和 Java API for XML 型 RPC (JAX-RPC) 程式設計模型。JAX-WS 是延伸 JAX-RPC 程式設計模型所提供之基礎的下一代 Web 服務程式設計模型。 當使用策略性 JAX-WS 程式設計模型時,透過支援標準型註釋模型,簡化了 Web 服務和用戶端的開發工作。 雖然仍支援 JAX-RPC 程式設計模型和應用程式,但請利用易於實作的 JAX-WS 程式設計模型來開發新的 Web 服務應用程式和用戶端。best-practices

About this task

To develop web services based on the JAX-WS programming model, you can use a bottom-up development approach starting from existing JavaBeans or enterprise beans or you can use a top-down development approach starting with an existing Web Services Description Language (WSDL) file. This task describes the steps when using the bottom-up development approach.

When developing JAX-WS web services starting from existing JavaBeans or enterprise beans, you can expose the bean as a JAX-WS web service by using annotations. Adding the @WebService or @WebServiceProvider annotation to the bean defines the bean as a JAX-WS web service. JAX-WS web services can optionally use a service endpoint interface. In addition to annotating the bean and the optional service endpoint interface, you must assemble all the artifacts that the web service requires, and deploy the resulting application into the application server environment to complete the process of enabling the bean as a web service. Although the use of a WSDL file is considered a best practice, you are not required to package a WSDL file with your JAX-WS web services.

Considerations when using JavaBeans
  • JavaBeans exposed as JAX-WS web services are supported only over an HTTP transport.
  • JavaBeans may use Contexts and Dependency Injection (CDI). Note that constructor injection is not supported.
Considerations when using enterprise beans
  • The enterprise bean must be a stateless or singleton session bean.
  • Enterprise beans that are exposed as JAX-WS web services must be packaged in EJB 3.0 or higher modules.
  • JAX-WS applications containing enterprise beans must be deployed with the endptEnabler command.
  • JAX-WS web services using enterprise beans are supported over an HTTP or Java Message Service (JMS) transport.
  • Enterprise beans may use CDI. Note that constructor injection is not supported.
  • You can optionally include Web Services Description Language (WSDL) documents in the JAX-WS application packaging.

從 WebSphere Application Server 7.0 版和更新的版本開始,系統會掃描 Java EE 5 應用程式模組(Web 應用程式模組 2.5 版或更新版本,或是 EJB 模組 3.0 版或更新版本)中是否有註釋可識別 JAX-WS 服務和用戶端。 不過,為了效能考量,依預設,系統不會掃描 Java EE 5 之前的應用程式模組(Web 應用程式模組 2.4 版或更早版本,或 EJB 模組 2.1 版或更早版本)中是否有 JAX-WS 註釋。在 6.1 版 Feature Pack for Web Services 中,預設行為是在應用程式安裝期間,掃描 Java EE 5 之前的 Web 應用程式模組來識別 JAX-WS 服務,以及掃描 Java EE 5 之前的 Web 應用程式模組和 EJB 模組,來尋找服務用戶端。由於 WebSphere Application Server 7.0 版及更新版本的預設行為是不在安裝應用程式或啟動伺服器期間掃描 Java EE 5 之前的模組是否含有註釋,因此為了保留與舊版特性套件的舊版相容性,您必須在伺服器上配置 Web 應用程式保存檔 (WAR) 的 META-INF/MANIFEST.MF 中的 UseWSFEP61ScanPolicy 內容或 EJB 模組,或定義 Java 虛擬機器自訂內容 com.ibm.websphere.webservices.UseWSFEP61ScanPolicy,來要求在安裝應用程式及啟動伺服器期間進行掃描。如果要進一步瞭解註釋掃描,請參閱 JAX-WS 註釋資訊。

Procedure

  1. Set up a development environment for web services. You do not have to set up a development environment if you are using Rational® Application Developer.
  2. Develop JAX-WS web services with annotations.
  3. Generate Java artifacts for JAX-WS applications.

    Use JAX-WS tooling to generate the necessary JAX-WS and JAXB artifacts needed for JAX-WS web services applications when starting from JavaBeans or enterprise beans components.

    If you are developing a service implementation bean that is invoked using the HTTP transport, then the WSDL file generated by the wsgen command-line tool during this step is optional. However, if you are developing a service implementation bean that is invoked using the SOAP over JMS transport, then the WSDL file generated by the wsgen tool during this step is required in subsequent steps, and therefore, not optional.

  4. (optional) Enable MTOM for JAX-WS web services. You can use SOAP Message Transmission Optimization Mechanism (MTOM) to optimize the transmission of binary attachments, such as images or files along with web services requests.
  5. (optional) Enforce adherence to WSDL bindings in JAX-WS web services. You can use the RespectBindingFeature to control whether a JAX-WS implementation is required to respect the contents of a wsdl:binding that is associated with an endpoint.
  6. (optional) Develop and configure a webservices.xml deployment descriptor for JAX-WS applications. You can optionally use the webservices.xml deployment descriptor to augment or override application metadata that is specified in annotations within your JAX-WS web services.
  7. Complete the implementation of your web services application.
  8. (Optional) Customize URL patterns in the web.xml file. When JavaBeans are exposed as JAX-WS endpoints, you can optionally customize the URL patterns within the web.xml deployment descriptor contained in the web application archive (WAR) file.
  9. Assemble the artifacts for your web service.

    Use assembly tools provided with the application server to assemble your Java-based web services modules.

    If you have assembled an EAR file that contains enterprise beans modules that include web services, use the endptEnabler command-line tool or an assembly tool before deployment to produce a web services endpoint WAR file. This tool is also used to specify whether the web services are exposed using SOAP over Java Message Service (JMS) or SOAP over HTTP.

  10. Deploy the EAR file into the application server. You can now deploy the EAR file that has been configured and enabled for JAX-WS web services onto the application server.
  11. Test the web service to make sure that the service works with the application server.

Results

You have developed a JAX-WS application.


指出主題類型的圖示 作業主題



時間戳記圖示 前次更新: July 9, 2016 11:18
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=twbs_devwbsjaxws
檔名:twbs_devwbsjaxws.html