Chapter 3. Web Services

Create Web services from EJB sources

RAD V6.0 also supports creating a Web service based on a standard (non-EJB) JavaBean. However, best practices recommend basing Web services on stateless session EJBs because they can be accessed securely in a consistent manner across all possible interfaces (Web, thick client, EJB, messaging).

Prerequisites:

  • Create an Enterprise Application project (Chapter3EAR).

  • Create an EJB project (Chapter3EJB).

  • Create or import an enterprise bean into your EJB project (SayHello bean with REMOTE client view).

  • Deploy your enterprise bean.

  • Create a dynamic Web project (Chapter3Web) targeted to the appropriate server (WAS 6.0). It is strongly suggested that you start the server before running the Web service wizard since it may take several minutes to start the WebSphere Application Server depending on the speed of your computer. To start the server, select it in the Servers view (Window > Show View > Servers), right-click and click Start.

  1. Ensure that the test server is running.

  2. From the Project Explorer, select EJB Projects > Chapter3EJB > Chapter3EJB > Sessions Beans > SayHello, and right-click Web Services > Create Web service.

    Create Web service

  3. From the Web Services popup, ensure that Web service type is set to EJB Web Service, and click Next. All other settings default to the selections and values in the following illustration:

    Create Web service - EJB Web Service

  4. From the Object Selection Page pop-up, ensure that the SayHello is selected under Stateless EJB beans, and click Next.

    Create Web service - Object Selection Page

  5. At the Service Deployment Configuration pop-up, if Web service runtime: is set to IBM WebSphere and Server is set to 000-257 (your test server), then click Next.

    Create Web service - Service Deployment Configuration

  6. At the Web Services EJB Configuration pop-up, perform the following tasks:

    Ensure that Use an existing service endpoint interface is cleared.

    Ensure that Select Router Project is Chapter3Web.

    Ensure that Select transports is SOAP over HTTP.

    Click Next.

    Create Web service - Web Services EJB Configuration

  7. At the Web Service Java Bean Identity pop-up, ensure that greet(...) is selected, and click Next. All other settings should default to the selections and values shown in the following illustration:

    Create Web service - Web Service Java Bean Identity

    WS-I compliance requires using Document/Literal (under Style and Use).

  8. At the resulting Web Service Publication pop-up, click Finish. Do not publish to any of the UDDI registries.

    Create Web service - Web Service Publication

Modify the WSDL to remove HTTPS

The WSDL is generated using the secure https://localhost:9443 because RAD V6.0 is configured to interact with the test server in secure mode.

The Web service can be accessed over the HTTPS or HTTP. Since the HTTPS and HTTP interaction is handled by the embedded HTTP server in the Web container, the back end Web service code is unaware of which protocol is used.

Follow these steps to change the WSDL address from HTTPS to HTTP:

Select EJB Projects > Chapter3EJB > ejbModule > META-INF > wsdl > SayHello.wsdl, and double-click to open.

At the SayHello.wsdl editor switch to the Source tab, scroll to the bottom, and change the SOAP address line from the following:


<wsdlsoap:address location="https://localhost:9443/Chapter3Web/services/SayHello"/>
					
					

to the following, ensuring that you change BOTH https to http AND 9443 to 9080:


<wsdlsoap:address location="http://localhost:9080/Chapter3Web/services/SayHello"/>
					
					

Save and close.

Do the same for \Chapter3Web\WebContent\wsdl\by\iba\rad257\SayHello.wsdl and Chapter3Web\WebContent\WEB-INF\wsdl\SayHello.wsdl.

Test Web Service using Web Service Explorer:

Web Service Explorer

BOOT.BY - Tech Industry News         Free SCBCD 1.3 Study Guide     Free SCDJWS 1.4 Study Guide     SCDJWS 1.4 Quiz     Free IBM Certified Associate Developer Study Guide     Free SCJP 5.0 (Tiger) Study Guide     Free Mock Exam Engine     Free SCWCD 1.4 Study Guide     IBM Test 000-287. Enterprise Application Development with IBM WebSphere Studio, V5.0 Study Guide     Free SCBCD 5.0 Study Guide