You will now start constructing the InSys Web service. You will need to create the following three files:
The CGI script is given next. Name the file productinfo.cgi and store it in the cgi-bin folder of your Apache installation.
The CGI script, as you can see, simply redirects all calls to the package ProductInfo. Next, you need to create the package, which will handle all queries from the client. The package will support the following methods:
The code chooses its data from a file databaseschema.conf, so the database file must be in the same folder as the script. First, the text file that contains the data is opened. If the file is not opened, the script exits.
In the preceding script, the file is opened first. If it's successful, its contents are read into a variable and the file is closed. The getProductInfo() method accepts two parameters. We will look at the SOAP message that the client sends when asking for the price of a product, such as Handspring Treo. The bold portions of the following code give the input values from the client application.
When the getProductInfo() method receives this data, the method checks the value of the second parameter. The values that are sent are accessible through a perl-define array
Because the first value in the array contains the name of the script, it is shifted out. The first value in the array is the product name as passed by the client and the second value is the information that is required.$second=$_;
The product name is stored in a variable, and the second value is checked against possible values to determine the method to be called. For example, if the value is price, then the method getProductPrice() is called.
Next, you will look at the getProductPrice() method. Each of these methods creates a search pattern depending on the information required, and a pattern search is made in the text database file. Perl is the best language to use for pattern matching because it has a lot of built-in commands and syntaxes specifically for this task, which is normally not available in other programming languages.
Before you continue, you need to look at the data source text file to learn how the data is stored in it and what pattern you can use to search for a particular piece of information. The following is a segment of the data in a flat text file. Save the file as
Handspring Treo models are favorites of reviewers for theirexpansion slots. By plugging various modules (sold separately) into this unit's"Springboard," you can turn it into a cell phone, digital camera, or MP3 player, among other applications. The Prism has a color screen in addition to 8MB of memory on the Palm OS. Experts say you'll get more battery life out of this color PDA than a comparable Pocket PC color unit—over 12 hours. Keep in mind, however, that monochrome models like the CLIE, above, can run for weeks without a recharge."
We have reproduced only the data for Product1. As is evident from the content of the preceding file, the pattern to search when you want to look up the price is company.product1.price. The method getProductPrice() should search for this pattern. However, it cannot be specific to a product. Therefore, you need to use the variable $second, which stores the product name. The search pattern then becomes company. $second. price. Here is the code for searching for the pattern:
All other methods use a similar pattern search and return appropriate values. Save the package file as ProductInfo.pm. Following is the complete code for the package:
Now that the Web service is ready, we will turn our attention to creating a client for this Web service.
The client application consists of two parts:
The script decides which part of the form to display depending on the variable flag that is used. When the input form is to be displayed, the default value of the variable is 0. However, when the form is submitted, a hidden field sets the value to 1 and the script retrieves the data from the server and displays it.
When you click the Submit button, the input form posts two values: the product and the information required on the product. Here is the code in the script that does that:
If you notice, the Select control has the name first and the set of radio buttons second. These are the names for the values that are sent to the script after the form has been posted. Here is the code that extracts the name-value pairs:
These values are passed to the Web service's getProductInfo() method. The code for doing this is shown next:
The returned values are then displayed within a table. Save the client application as Webservice.pl. Here is the complete code for the client application:
Ensure that all three files you created are in the <Apache Web Server_Home> cgi-bin folder. Try the application by connecting to the client using http://localhost/cgi-bin/webservice.pl. The client interface before the Web service is invoked is shown in Figure.
The Web Service Client
The reply from the Web service is shown in Figure.
Result of Querying the Web Service
XML Related Interview Questions
|Soap Tool Interview Questions||HTML Interview Questions|
|PHP Interview Questions||ASP.NET Interview Questions|
|PHP5 Interview Questions||Java Interview Questions|
|CSS Interview Questions||XSLT Interview Questions|
|Java XML Interview Questions||XMLHttpRequest (XHR) Interview Questions|
|ebXML Interview Questions||XML DOM Interview Questions|
|XML-RPC Interview Questions||XSD Interview Questions|
|Soap Web Services Interview Questions||XSL Interview Questions|
|Xml Publisher Interview Questions|
Basics Of Xml
Basics Of Web Services
Introduction To Soap
Introduction To Uddi
Introduction To Wsdl
Creating A Web Service Using The Microsoft Soap Toolkit
Building Web Applications On The .net Platform
Creating An Asp.net Web Service
Creating A Web Service From An Interface
Introduction To The Atl Server
Creating A Web Service Using The Atl Server Library
Design And Creation Of The Knowledge Share Web Service
Introduction To Java Xml Technologies
Developing Java Web Services
Design And Creation Of A Web Service Using The Ibm Toolkit
Introduction To Mobile Applications
Creating A Mobile Application That Consumes A Web Service
Web Services Development With Jdeveloper
Creating Web Services Using Perl
Integration Of Xml Web Services With The Office Xp And Sql
Server 2000 Toolkits
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.