Transforming an EJB into a Web Service
Now its CWE's turn. In this case, the business logic is already written, as shown in CWEPickUp.ejb. The code is very similar to that of the Euro-Ship web service, except that it requires RMI to be accessed.
Transforming this EJB into a web service is easy. The first step is to create a new web service project, including a blank web service. Choose File, New, Project. Select the category Web Services, and then Web Service Project. Enter the name CWE_WS_Adaptor. Then create an empty folder by right-clicking the new project and selecting New, Folder. Type the name wsadaptor. This will become our package structure, as some files require this setup.
Inside the new folder, create a web service by right-clicking the folder and choosing New, Web Service. The file name will be CWE_WS_Adaptor.jws. You're now in Design view for this new web service. Let's insert an EJB control: Insert, Controls, EJB Control, and enter the information shown in Figure 4.
Figure 4 Inserting an EJB control.
The JNDI information can be retrieved by clicking the button called Browse Application EJB. Select the Remote JNDI variety, as our applications will probably run on unrelated servers. Click Create. The control appears in the web service. Go to the Data palette to your right and expand cwePickUp. After that, drag-and-drop the method name pickup() from the Data palette to the Design view.
Let's generate more stuff. Right-click CWE_WS_Adaptor.jws and select Generate WSDL File. This file will help third-party users to learn about the service. For example, this file will be used by the Euro-Ship service.
Our EJB now has a web service adapter in front. If CWE has a system driven by JMS, email, or even a database, turning it into a web service would require similar steps, plus a bit of programming.