Creating a Web Service by Using the WSTK XML

Before creating a Web service by using the WSTK, we will discuss the toolkit in general.

The WSTK contains several tools that help you to create, discover, and invoke a Web service. These tools are explained in the following list:

  • Runtime API for the client side. This API implements the discovery and proxy functionality for the implementation of IBM's open source. IBM's open sources include the SOAP implementations, WSDL for Java (WSDL4J), and UDDI for Java (UDDI4J).
  • Runtime API for the server side. This API deploys and exposes Axis-based Web services.
  • Sample code. This helps you understand the creation of Web services by using the WSTK.
  • HTTPr. This is an extension of the standard HTTP protocol. HTTPr adds messaging capabilities to your Web service and is present in the %WSTK_HOME%HTTPR directory. The WSTK contains both the reference and demo version of HTTPr.
  • Apache Axis. This is the latest version of open source SOAP implementation from the Apache Software Foundation. The Axis toolkit offers better performance and flexibility than its earlier versions.
  • SOAP digital signatures and encryption. These specifications define the methods in which encrypted data within a SOAP message can be included within the SOAP header.
  • XKMS. This is an emerging standard for accessing and managing public key infrastructure services. These services are based on the Web services architecture. The WSTK implements two components of XKMS: XML Key Information Service Specification (X-KISS) and XML Key Registration Service Specification (X-KRSS).
  • Utility services. These are pluggable service interfaces that you can use to plug additional functionalities into the WSTK.

Creating the Web Service

To create a Web service, you first create a Java class file. In this case, because you are creating a credit card validation Web service, you need to use the CCheck.java file. Compile the .java file to create the .class file.

The next step is to create a WSDL file from the class file that you created. To do this, you use the java2wsdl.bat file present in the WSTK_HOMEin folder. Create a folder Ccheck in the < WSTK_HOME> services applications folder. The command to create a WSDL file is shown in the following example:

As you can see, the preceding code uses the java2wsdl command, which has several options, as explained in Table.

Options Used with the java2wsdl Command

Options Used with the java2wsdl CommandOptions Used with the java2wsdl Command

The java2wsdl command creates a WSDL file. The content of this file is as shown:

Creating the Deployment Descriptor

The deployment descriptor is a file, usually in the XML format, which stores the data used to deploy a Java application. Version 3.0 of the WSTK uses the old version of the deployment descriptor instead of the WSDD version. Therefore, you need to create the deployment descriptor. You can do this by using the following code:

Creating a Folder Structure for the WSTK

A folder structure for the WSTK includes a root folder containing all Web service files that are deployed by using the WSTK.

Tip?/td>
You need to create the exact folder structure for each Web service that you deploy using the WSTK. Therefore, it is advisable that you replicate the folder structure for the sample Web services created by using the toolkit to create the folder structure for your Web service.

Whenever you want to deploy a new service, create a new folder under the Applications directory. This folder should contain at least three subdirectories, as discussed in the following list:

  • client. This subdirectory contains the client files that are associated with the Web service.
  • deployment. This subdirectory contains the deployment files that are associated with the Web service.
  • webapp. The contents of this subdirectory must conform to the standard WAR file structure. However, an exception to the standard WAR file structure is the import.XML file located in the META-INF directory. The import.xml file contains a list of all JAR files and other files that the service requires to run.

The contents of the import.xml file are as shown:

The preceding code uses the fromdir attribute to indicate a path to the source file relative to %WSTK_HOME%. The files identified by the fromdir attribute are copied into the directory indicated by the todir attribute. However, you need to copy the actual class file for the CCheckServer class to the WEB-INFclasses folder.

The WEB-INF folder contains a web.xml file, which is a standard Java Web application deployment descriptor. This file deploys the AxisServlet that is used as the entry point for the service. The contents of the web.xml file are shown in the following code:

Deploying the Web Service

After you create the directory structure, you need to deploy the Web service on the Tomcat server. To do this, perform the following steps:

  1. Execute the wstkconfig.bat file from the WSTK_HOMEin folder. The tool launches and displays a dialog box, as shown in Figure.
  2. Running WstkConfig

    Running WstkConfig

  3. Click on the Configure Services tab and select your Web service, as shown in Figure, and click Next.
  4. Selecting the Web Service to be Deployed

    Selecting the Web Service to be Deployed

  5. Click on the Configure UDDI tab, and then click on the Finish button.

Performing these steps deploys the WAR files. Next, you need to perform an additional task:registering the Web service with the Axis toolkit. The following section discusses this.

Registering the Web Service with the Axis Toolkit

Copy the file deploy.bat from one of the sample applications in the <WSTK_HOME> servicesapplications folder and use it to deploy your Web service. The command used to register a Web service with the Axis toolkit is as follows:

In the case of the CCheck Web service, the command would be as follows:

After you execute the previous command, your Web service is ready to be used. You can use the following client code to test the Web service:

However, the steps followed in the previous sections to create and deploy a Web service can be tedious and time consuming, especially when you need to deploy large-scale Web services. Therefore, IBM provides you with a complete commercialIDE, which simplifies greatly the task of building all kinds of J2EE applications, including Web services t,the Websphere Studio Application Developer.



Face Book Twitter Google Plus Instagram Youtube Linkedin Myspace Pinterest Soundcloud Wikipedia

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

XML Topics