Creating a web service from an enterprise bean (EJB) using the WebSphere JAX-RPC runtime environment

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.

Before you begin

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.

About this task

Note: This product supports enterprise bean web service creation from stateless session enterprise beans.

Create a web service from an enterprise bean

Procedure

  1. Switch to the Java™ EE perspective ( Window > Open Perspective > Java EE).
  2. In the Enterprise 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 Bottom up EJB Web service from the Web service type drop down list. Select the service implementation the from the stateless session enterprise beans available in your workspace. You can optionally choose to do the following:
    1. Select the stages of web services development that you want to complete using the slider. This will set several default values on the remaining wizard panels.
      • Develop: this will generate the WSDL definition and implementation of the web service. This includes such tasks as creating the modules which will contain the generated code, WSDL files, deployment descriptors, and Java files when appropriate.
      • Assemble: this ensures the project that will host the web service or client gets associated to an EAR when required by the target application server. Router modules will be created in this stage.
      • Deploy: this will create the deployment code for the service.
      • Install: this will install and configure the Web module and EARs on the target server. If any changes to the endpoints of the WSDL file are required they will be made in this stage.
      • Start: this will start the server once the service has been installed on it.
      • Test: this will provide various options for testing the service, such as using the Generic Services Client, Web Service Explorer or sample JSPs. Note that you can only use the Web Services Explorer to test web services which use HTTP transports.
    2. Select your server: the default server is displayed. If you want to deploy your service to a different server click the link to specify a different server.
    3. Select your runtime environment: the default runtime environment is displayed. If you want to deploy your service to a different runtime environment click the link to specify a different runtime.
    4. Select the service project: the project containing the project selected in your workspace is displayed. To select a different project and EAR click on the project link. Ensure that the project selected as the Client Web Project is different from the Service Web Project, or the service will be overwritten by the client's generated artifacts.
    5. If you want to create a client, select the type of proxy to be generated and repeat the above steps for the client.
    6. Publish the Web service: this will launch the Web Services Explorer to publish your web service to a UDDI registry.
    7. Monitor the Web service: this will 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. Alternately you can manually set up a TCP/IP monitor as described in Using the TCP/IP Monitor to test web services. Note that you can only monitor web services which use HTTP transports. Additionally, if you are routing web service traffic through the TCP/IP monitor you cannot test the web service using the Universal Test Client.
  5. Web Service EJB Configuration page:
    1. 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.
    2. Select your binding type and router project. Enter the router project name for each type of binding selected.
    3. Set the SOAP action. This option is used to set the soapAction field in the generated WSDL. Default sets the soapAction field according to the deployment information. None sets the soapAction field to double quotes (""). Operation sets the soapAction field to the operation name.
    4. You can also choose to exclusively map MIME types using WSDL 1.1 standards. If the MIME type cannot map to WSDL 1.1 standards (for example, if the attachment is an array or a Java bean property), the command fails.
  6. EJB Web Service Binding Configuration page: If you selected EJB or JMS binding on the previous page, enter the information for the bindings.
    • JMS destination type: Select either queue or topic as your destination type.
    • JMS destination: The JNDI name of the destination queue or topic.
    • JMS connection factory: The JNDI name of the connection factory.
    • JMS target service: The name of the port component to which the request will be dispactched.
    • JMS listener input port: Name of the listener input port to be associated with the message driven bean (MDB).
    • JMS initial context factory: The name of the initial context factory to use. This is mapped to the java.naming.factory.initial property.
    • JMS jndi provider URL: This is mapped to the java.naming.provider.url property.
    • JMS delivery mode: Indicates whether the request message should be persistent or not.
    • JMS time to live: The lifetime in milliseconds of the request message. A value of 0 indicates an infinite lifetime.
    • JMS priority: The JMS priority associated with the request message.
    • JMS user ID: The user ID to be used to gain access to the connection factory.
    • JMS password: The password to be used to gain access to the connection factory.
  7. 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:
    • Change the WSDL port name if required.
    • Change the WSDL file name or path if required. Any path information you provide in this field will create folders within the META-INF/wsdl folder. This can be useful if you do not want to overwrite WSDL or XSD files already in the default folder.
    • The methods panel shows a summary of methods in your bean. You can select to include or remove methods from the generated web service.
    • Set the void return - this field is for a web service method with return type of void that describes whether a response is expected from the web service. Oneway: methods with void returns are one-way. This argument is the default for a JMS transport. Twoway: Methods with void returns are two-way. This argument is the default for an HTTP transport.
    • 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.
    • Specify extra and stop classes. Extra specifies other classes that are represented in the WSDL file. You can use the -stopClasses argument to define additional classes that cause the search to stop.
  8. Web Service Package to Namespace Mappings page: The web services wizard generates a WSDL file from the specified Java bean. By default it will create a namespace based on the package name of the Java bean. To override this default behavior you can specify your own namespaces to be generated in the WSDL file. If you selected Define custom mapping for package to namespace on the previous page, you can enter your custom mapping pairs on this page 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. You will need to escape some special characters in the properties files. For example somePackage=http://someNamespace should be somePackage=http\://someNamespace. Otherwise, the colon (:) would be treated as delimiter resulting in trying to map somepackage to http. For more information about formats for properties files in Java, refer to: Java Platform API documentation: java.util.Properties load method.
  9. 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 or Generic Services Client. 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.
  10. 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.
  11. Web Service Client Namespace to Package Mappings page: if you selected Define custom mapping for namespace to package on the previous page, you can enter your custom mapping pairs on this page 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 namespace=package. You will need to escape some special characters in the properties files. For example http://someNamespace=somePackage should be http\://someNamespace=somePackage. Otherwise, the colon (:) would be treated as delimiter resulting in trying to map http to //someNamespace=somePackage. For more information about formats for properties files in Java, refer to: Java Platform API documentation: java.util.Properties load method.
  12. 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. Note that if you are routing web service traffic through the TCP/IP monitor that you cannot test the web service using the Universal Test Client.
    • 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.
  13. 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
  14. 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 sample 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.

Results

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.


Feedback