Using the Websphere Studio Application Developer XML

As discussed, the Websphere Studio Application Developer makes the task of developing Web services simple. In this section, you will create the credit card validation Web service by using the studio. In addition, you will learn to develop a sample client application by using the studio.

To create a Web service, you first need to create a Web project.

Creating a Web Project

Follow these steps to create a Web project:

  1. Start the Websphere Studio Application Developer.
  2. Create a new Web project by selecting the File, New, Web Project options. The Define the Web Project page opens, as shown in Figure.
  3. Creating a Web Project

    Creating a Web Project

  4. Specify the name of the project and the EAR container for the project.
  5. Click on the Next button. The Define Java Build Settings page is displayed, as shown in Figure.
  6. Defining Java Build Settings

    Defining Java Build Settings

  7. The first tabbed window allows you to specify the source folder for the project. Accept the default values.
  8. The next tabbed window, Projects, allows you to include any other projects while building the project (see Figure).
  9. The Projects Tab

    The Projects Tab

  10. Click on the Libraries tab. The window is displayed, as shown in Figure. Because XML is used, you need to specify the build path to the JAR file with the parser.
  11. The Libraries Tab

    The Libraries Tab

  12. Click on the Add External JARs button.
  13. Browse to the plugins/com.ibm.etools.websphere.runtime/runtime folder and select xerces.jar.
  14. Click on the Finish button to complete the creation of the Web project.

Importing the Java File

Next, you need to import the Java file that contains the credit card validation code. To import the Ccheck.java file, perform the following steps:

  1. Select Import from the File menu. The Import Wizard starts, as shown in Figure.
  2. The Import Wizard

    The Import Wizard

  3. In the wizard, select File System and click on the Next button. The File System pane of the wizard is displayed, as shown
  4. The File System Pane of the Wizard

    The File System Pane of the Wizard

  5. Click on the Browse button next to the Directory text box and select the folder containing the Ccheck.java file.
  6. Next, select the directory name check box.
  7. Click on the Select Types button. The Select Types dialog box is displayed, as shown in Figure.
  8. The Select Types Dialog Box

    The Select Types Dialog Box

  9. Select the check box next to *.java and click on the OK button to close the window.
  10. Double-click on the folder name. A list of all files of the types you selected appears on the right side.
  11. Select the Ccheck.Java file, as shown in Figure.
  12. Importing the Java Source File

    Importing the Java Source File

  13. Specify the folder where you need to copy the files that you have selected.
  14. Click on the Browse button next to the Folder text box and select the folder where you want to import these files.
  15. Click on the Finish button to close the Import Wizard.

Creating the Web Service

To create the Web service, perform the following steps:

  1. Select the New, Web Services option from the File menu. The Select page appears, as shown in Figure.
  2. Creating a Web Service

    Creating a Web Service

  3. Click on the Next button. The Web Service Wizard starts.
  4. Select the Web project to which you want to add the Web service.
  5. Click on the Next button. The Web Service Type selection pane is displayed, as shown in Figure.
  6. The Web Service Type Selection Pane

    The Web Service Type Selection Pane

  7. From the available files, select Ccheck.Java.
  8. Click on the Next button. The Web Service Java Bean Identity pane is displayed, as shown in Figure.
  9. The Web Service Java Bean Identity Pane

    The Web Service Java Bean Identity Pane

  10. Change the scope from Application to Session. This ensures that a new object foreach user is created so that caching of the service works properly for each user.
  11. Click on the Next button. The Web Service Java Bean Methods pane is displayed, as shown in Figure.
  12. The Web Service Java Bean Methods Pane

    The Web Service Java Bean Methods Pane

  13. Select the isvalid() method. You can decide whether to use the encoding style by the Web service.
  14. Click on the Next button. The Web Service Java to XML Mappings pane is displayed, as shown in Figure.
  15. The Web Service Java to XML Mappings Pane

    The Web Service Java to XML Mappings Pane

  16. Click on the Next button. The Web Service Proxy Generation pane is displayed, as shown in Figure.
  17. The Web Service Proxy Generation Pane

    The Web Service Proxy Generation Pane

  18. Select the Generate a Proxy check box to create a proxy for the Web service, which you can further use to build Web service clients.
  19. Click on the Next button. The Web Service Client XML to Java Mappings pane is displayed, as shown in Figure.
  20. The Web Service Client XML to Java Mappings Pane

    The Web Service Client XML to Java Mappings Pane

  21. Click on the Next button. The Web Service Sample Generation pane is displayed, asshown in Figure.
  22. The Web Service Sample Generation Pane

    The Web Service Sample Generation Pane

    Note?/td>Note that the Web Services Sample Generation pane is only active if you chose to create the proxy previously.

  23. Select the Generate a Sample check box. The other controls are then activated.
  24. Check the Launch the Sample check box and click on the Finish button to create the Web service, create a client application for the Web ervice, and launch the client application.

The preceding steps create two WSDL files that contain the service and interface details of the Web service. These files are discussed in the following sections.

WSDL Service File

The IDE creates a implementation WSDL document and an interface WSDL document. The content of the interface WSDL for the Web service file is as shown:

WSDL Interface File

The following code is the content of the WSDL document, which defines the interface of the Web service:

Apache SOAP Deployment Descriptor

In addition to the WSDL service and interface files, the studio creates an earlier version of the Apache SOAP deployment descriptor. The descriptor is stored in the CCheck.isd file. The following code shows the content of this file:

The IDE creates and uses an earlier version of the deployment descriptor. Compare this with the newer deployment descriptors we have already discussed. The preceding code uses the id attribute of the service element, which identifies the Web service requestors. Next, the scope attribute controls how the SOAP server handles the requests for the service. As you can see, the value of the scope attribute is set to Session. This implies that a separate service instance is created for each user session.

The value for the scope attribute also can be Application. In such a situation, one service instance handles all requests. Another alternative for the value of the scope attribute is Request. In such a situation, a new service instance handles each new request. The class attribute of the Java element identifies the class that implements the Web service.


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

XML Topics