Creating a Web service from an enterprise bean (EJB) using the WebSphere run-time environment

Prerequisites:

The Web service you are creating acts as a client to the enterprise bean. The enterprise bean must be deployed before launching the Web service wizard.

The Web Service wizard assists you in creating a new Web service, configuring it for deployment, and deploying the Web service to a server. Once your Web service is deployed, the wizard assists you in generating the client proxy and sample application to test the Web service. When you have completed testing, you can publish your Web service to a UDDI Business Registry using the Export wizard.

For more information on EJB application development, refer to EJB tools.

Note: Rational Developer products support enterprise bean Web service creation from stateless session enterprise beans.

Create a Web service from an enterprise bean

  1. Switch to the J2EE perspective ( Window > Open Perspective > J2EE).
  2. In the Project Explorer view, expand EJB Modules and select the session bean from which you want to generate your Web service.
  3. Click File > New > Other. Select Web Services in order to display the various Web service wizards. Select the Web Service wizard. Click Next.
  4. Web Services page: select EJB Web service from the Web service type drop down list. You can optionally choose to do the following:
    • Start the Web service in a Web project - if you do not select this option you will have to manually start the Web service. You must select this option to enable the other options on this page.
    • Launch the Web Services Explorer to publish your Web service to a UDDI registry.
    • Generate a Java™ bean client proxy to the Web service. The Java bean client proxy that is generated provides a remote procedure call interface to the Web service.
    • Test the Web service - this allows you to test the Web service in the Web Service Explorer before a proxy is generated.
    • Send the Web service traffic through the TCP/IP Monitor, which allows you to watch the SOAP traffic generated by the Web service and to test this traffic for WS-I compliance.
  5. Object selection page: If you selected the session bean before starting the wizard, the fields on this page should be prefilled. If they are not, click Browse EJB Beans. In the window that opens, select the EAR project that contains the enterprise bean that will be used to generate the Web service - this will populate the table below with the stateless enterprise beans contained in this EAR.
  6. Service Deployment Configuration page: specify the server and client deployment settings.
    1. Click Edit and select the IBM® WebSphere® run-time environment and select the server on which you want to run your Web service and Web service client. If you want to use the IBM SOAP run-time environment or the Apache Axis 1.0 run-time environment, refer to the appropriate task.
    2. Select the Service project and EAR for your Web service. The wizard will create these for you if they do not already exist.
    3. Select the type and name of project in which you want the Web service client created. If you enter the name of an existing project, the project type field must match that of the existing project. If you enter a name of a project that does not already exist, the wizard will create the project for you. Note that the only project type supported for Axis and SOAP run-time clients is a Web project. If you want the client to be created in a Java, EJB, or Application Client project, you must select the WebSphere run-time environment for your client.
    4. Select an existing EAR or enter a unique name to associate the Web service client with a different EAR than the Web service EAR. Note: Selecting different EARs for the Web service and Web service client can reduce the chance of encountering run time errors, but will use more system resources.
  7. Web Service EJB Configuration page: Select your Router project (which must be a pre-existing EJB project). If you have a pre-existing service endpoint interface, you can select to use it. Alternately, the Web services wizard will generate one for you. Select the transport type: SOAP over HTTP or SOAP over JMS. If you select JMS, complete the required JMS URI properties. Select any field and press F1 for more information on each field.
  8. In the Web Service Java Bean Identity page: this page lists the Web service URI, and the location of the generated WSDL file. You have the following options on this page:
    • The methods panel shows a summary of methods in your bean. You can select to include or remove methods from the generated Web service.
    • Select the style and encoding of the Web service. Only Document/Literal is WS-I compliant.
    • Select to enable security. Enabling security will make the Web service WS-I non-compliant.
    • Define customized package to namespace mappings.
  9. Web Service Package to Namespace Mappings page: if you selected Define custom mapping for package to namespace on the previous panel, you can enter your custom mapping pairs on this panel by clicking Add. Alternately, you can click Import to import custom mapping pairs from a .properties file. The content of the properties file must be of the format package = namespace .
  10. Web Service Test page: If you selected to test the Web service, select the test facility for the generated Web service, and click Launch. This will open the Web service in the Web Services Explorer. Select the operation you want to test, enter the required information, and click Go. The result will display in the Status pane. When you have tested the Web service, close the browser window and click Next.
  11. If you have selected to generate a proxy, the Web Service Proxy page displays. The client proxy provides a remote procedure call interface to your Web service.  The folder of the Java client proxy defaults to / EJBWebProjectClient. You can optionally select to enable security for the generated proxy or define custom package to namespace mappings.
  12. Web Service client package to namespace mapping page: if you selected Define custom mapping for package to namespace on the previous panel, you can enter your custom mapping pairs on this panel by clicking Add. Alternately, you can click Import to import custom mapping pairs from a .properties file. The content of the properties file must be of the format package=namespace.
  13. If you have selected to test the generated proxy, the Web Service Client test page displays. Use this page to select the following options:
    • Select your test facility. You can test the generated proxy in the Universal Test Client or the Web Service Explorer, or you can generate a sample Web service JSP.
    • If you selected to test the proxy through a JSP, you can select the folder where the JSP will be located, and you can select the methods that will be included in the JSP.
  14. If you have selected to publish your Web service, use the Web Service Publication page to select which UDDI registry you will publish to. Click Finish
  15. After the Web service has been created, the following may occur depending on the options you selected:
    • If you have selected to test the generated proxy using Web service JSPs, the proxy is launched in a Web browser at the following URL: http://localhost: port/ EJBWebProjectClient/sampleBeanName/WebServiceName/TestClient.jsp You can use this sample application to test the Web service by selecting a method, entering a value for the method, and clicking Invoke. The result of the method will display in the results pane.
    • If you have selected to test the generated proxy using the Universal Test Client, it will be launched in a browser window at the following URL: http://localhost:9080/UTC/preload?object= BeanPackage. BeanServiceProxy. In the Reference pane, under Object References, expand the proxy stub to display the methods of the Web service. Click the method you want to test, enter a value in the Parameters pane, and click Invoke. The result will be generated below.
    • If you have selected to test the Web service using the Web Services Explorer, the Explorer will open. Select the operation you want to test, enter the required information, and click Go. The result will display in the Status pane.
    • If you have selected to publish the Web service, the Web Services Explorer is launched displaying the page required to publish your Web service to the IBM UDDI Test Registry. Follow the instructions in Publishing the Web service to complete this task.

For more information on EJBs, refer to the EJB application development documentation. For samples of creating a Web service from an EJB, refer to the Tutorials Gallery and Samples Gallery.

Terms of use | Feedback
(C) Copyright IBM Corporation 2000, 2005. All Rights Reserved.