You are on page 1of 24

Web Service

1.1 Web Service Definition


Web services describes a standardized way of integrating Web-based applications
using the XML, SOAP, WSDL and UDDI open standards over an Internet protocol
backbone. Web Services are meant to be interoperable, allowing you to talk to other
vendor implementations and hence removing vendor locking.
Thus

Web

Services

allows

different

applications

from

different

sources

to

communicate with each other without time-consuming custom coding, and because
all communication is in XML, Web services are not tied to any one operating
system or programming language.
1.2 Web Service Building Blocks
XML is used to tag the data, SOAP is used to transfer the data, WSDL is used for
describing the services available and UDDI is used for listing what services are
available.
Thus XML + HTTP form the basic Web services platform. The HTTP protocol is the
most used Internet protocol. XML provides a language which can be used between
different platforms and programming languages and still express complex messages
and functions. It allows designers to create their own customized tags, enabling the
definition, transmission, validation, and interpretation of data between applications
and between organizations.
Web services elements:

SOAP (Simple Object Access Protocol)

UDDI (Universal Description, Discovery and Integration)

WSDL (Web Services Description Language)

1.3 Reason for using Web services


Supports Interoperability
Web Services are platform and language independent since they are built using XML
standards. This feature makes them suitable for communication between any types
of application that resides on any platform.

Enhances Web Application


With the help of Web services, your application can publish its function or message to
the world.
Web services use XML to code and to decode data, and SOAP to transport it (using
open protocols).
With Web services, your accounting department's Win 2k server's billing system can
connect with your IT supplier's UNIX server.
Advantages of Web Services
a. Component Reuse.
Web services can offer applications components like currency conversion,
weather reports, or even language translation as services. Ideally, there will
be only one type of each application component, and anyone can use it in
their application.
b. Making use of existing software.
Web Service provides support for linking the data of different application and
hence supports interoperability. Web services allow exchange of information
between applications developed using different platform.
c. HTTP is one of the protocols used by Web Service to transfer data. Since HTTP
is supported by most of the browsers this becomes an added advantage of
Web Services.
Thus, Web Services can convert your applications into Web-applications. By using
Web services, your application can publish its function or message to the rest of the
world. The basic Web Services platform is XML + HTTP. Web services use XML to
code and decode your data and SOAP to transport it.
2. SOAP

2.1 SOAP Definition


Simple Object Access Protocol, a lightweight XML-based messaging protocol used Web
service request and response messages to encode the data before sending them over a
network. SOAP messages are independent of operating systems, technologies and
programming languages and hence can use different Internet protocol.

SOAP Building Blocks


A SOAP message is an ordinary XML document containing the following elements:

Envelope - Identifies the XML document as a SOAP message

Header - Contains header information

Body - Contains call and response information

Fault - Contains errors and status information

2.2 Reason for using SOAP


One of the most important requirements in the application development is to allow
exchange of data between the programs.
A better way to communicate between applications is over HTTP, because HTTP is
supported by all Internet browsers and servers. SOAP was created to accomplish
this.
SOAP provides a way to communicate between applications running on different
operating systems, with different technologies and programming languages.
2.3 Example for SOAP
In the example below, a GetCurrentNews request is sent to a server. The request has
a New Catergory parameter, and a News parameter will be returned in the response.
The namespace for the function is defined in "http://www.example.com/News"
address.
The SOAP request:
POST /InNews HTTP/1.1
Host: www.example.org
Content-Type: application/soap+xml; charset=utf-8
Content-Length: nnn
<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.sample.com/2008/12/soap-envelope"
soap:encodingStyle="http://www.sample.com/2008/12/soap-encoding">
<soap:Body xmlns:m="http://www.example.com/News">

<m:GetCurrentNews>
<m:NewsCat>Stock Market</m:NewsCat>
</m:GetCurrentNews>
</soap:Body>
</soap:Envelope>

A SOAP response:
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: nnn
<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.sample.com /2001/12/soap-envelope"
soap:encodingStyle="http://www.sample.com /2001/12/soap-encoding">
<soap:Body xmlns:m="http://www.example.com/News">
<m: GetCurrentNewsResponse>
<m:News>Rates have gone down in the International stock Market etc.</m:News>
</m:GetCurrentNewsResponse>
</soap:Body>
</soap:Envelope>

3. UDDI
3.1 UDDI Definition
Universal Description Discovery and Integration specification provides a platformindependent way of describing services, discovering businesses, and integrating
business services using the Internet.
UDDI data structure provides a standardized way for listing the business services
available as well for providing a brief description about the same, together with the
access information.

4. WSDL
4.1 WSDL Definition

Web Service Description Language, is a language for providing a standardized way


to interface with XML-based services.
WSDL is a document written in XML. The document describes a Web service. It
specifies the location of the service and the operations (or methods) the service
exposes.
5.

Web Service Testing

Load Runner can be used to create script for testing your Web Services. You can use
the VUGEN test generation wizard to automatically generate scripts, or create the
scripts manually. Both Desktop and Web application which involves Web Services can
be tested using Load Runner.
5.1 Manually creating script in Load Runner
Pre-requisite for manually creating the script.
1

WSDL files for the various Web Services used by the application.

List of the Web Services methods that are invoked for the scenario to be
scripted along with the input parameter and the connectivity between the
methods.

Note: We need the help of developers to find the set of web services invoked for a
particular scenario, their input and the connectivity between them.
When we have the WSDL files and the details of the methods invoked (which includes
the input parameter to be passed and the output parameters that has to be
captured) for a particular flow we can manually record the script by following the
below mentioned steps.
Step 1: Select Web Service Protocol and create and empty script
Click New Single Protocol Script and then select Web Service and click OK. This
creates and empty Web Service script.

Figure 1.1
Step 2: Import the necessary WSDL files
WSDL files can be imported by click on Manage Services. We can import as many
WSDL files as required.
WSDL files can be imported by using anyone of the options mentioned below

URL

File

UDDI

Quality Center

Figure 2.1

Figure 2.2

Figure 2.3
Step 3: Add the Service calls to the script in the required order
Click on Add Service. It shows the WSDL files that have been imported in the
Service drop down box and the operation supported by each of the WSDL file in the
Operation drop down box.
Now to add service call, first select the desired Service and then the Operation.
Input and output arguments corresponding to the operation selected are listed
below. In order to provide the input data select the required input variable and
provide the data in the Value box.
If you need to save any of the output parameter (i.e. correlate any value), select the
respective variable, check Save return value in parameter and provide the
parameter name. This way you can correlate as many values as required.
After providing the necessary input variables and capturing the required output
parameters, Click OK. A script gets generated to invoke service call with the input

data provided and it also takes care of the correlation (i.e. capturing the output
data).

Figure 3.1

Figure 3.2

Figure 3.3

Figure 3.4

Figure 3.5
Step 4: Repeat Step 3 to generate script for all the required service call.
5.2 Recording a Web Service script in Load Runner
Step 1: Select Web Service Protocol and create and empty script
Click New Single Protocol Script and then select Web Service and click OK. This
creates and empty Web Service script.

Figure 1.1
Step 2: Specify application to record.
You are provided with two options:
a. Record default Web Browser. It Records the actions of the default Web
browser, beginning with the specified URL. Select this option where you access the
Web Service through a Web-based UI.
b. Record any application. Records the actions of the client application. Specify or
browse for the path in the Program to record box. Specify any relevant arguments
and working directories.

Figure 2.1
Step 3: Make necessary changes to the configuration setting and click
Finish.
Application is invoked by the Vugen and it begins recording. We need to perform the
required action within the application and then click on the Stop button. The script
gets created automatically.
5.3 Enhancing the recorded script
5.3.1 Correlation:
Case 1: In order to capture a single value follow the below mentioned steps
a. Switch to Tree View.
b. Click on Server Response tab.
c. You can manual browse through server response of all the service call and
figure out where the value first appears. Else you can make use of Query
Builder and search for the value in each of service call individually.

d. Now right click on the value and select Save value in a parameter option.

e. Provide the name of the parameter and click OK.

Following piece of code gets added and this captures the required value
lr_xml_get_values("XML={response}",
"FastQuery=/Envelope/Body/UserDataResponse/UserDataResult/LoggedInUser/UserID",
"ValueParam=ParamValue_UserID",
LAST);

Case 2: In order to capture a multiple values follow the below mentioned steps
a. Switch to Tree View.
b. Click on Server Response tab.
c. You can manually browse through server response of all the service call and
figure out the set of values to be captured. In the below example
EmployeeID has to be captured. It appears in multiple node and all the
values has to be captured.

d. Now right click on the value and select Save value in a parameter option.
e. Provide parameter name and click OK.
f.

Step d and e has to be repeated for all the occurrences

Following piece of code gets added.


lr_xml_get_values("XML={response}",
"FastQuery=/Envelope/Body/EmployeeDetailResponse/EmployeeDetailResult/diffgram/EmployeeDetailData
/EmployeeDetail/EmployeeID",
"ValueParam=ParamValue_EmployeeID1",
LAST);
lr_xml_get_values("XML={response}",
"FastQuery=/Envelope/Body/EmployeeDetailResponse/EmployeeDetailResult/diffgram/EmployeeDetailData
/EmployeeDetail[2]/EmployeeID",
"ValueParam=ParamValue_ EmployeeID 2",
LAST);
lr_xml_get_values("XML={response}",
"FastQuery=/Envelope/Body/EmployeeDetailResponse/EmployeeDetailResult/diffgram/EmployeeDetailData
/EmployeeDetail[3]/EmployeeID ",
"ValueParam=ParamValue_ EmployeeID 3",
LAST);

We can retrieve all these three value using a single query by making the following
changes to any one of the query above:
lr_xml_get_values("XML={response}",
"Query=/Envelope/Body/EmployeeDetailResponse/EmployeeDetailResult/diffgram/EmployeeDetailData/*/
EmployeeID",
"ValueParam=ParamValue_EmployeeID",
"SelectAll=yes",
LAST);

In the above code * can take any value. Hence all the values from the server
response is captured
Note: A fast query can be used when the exact path to the information is known.
Fast query accepts single slashes, nodes, and brackets. It is used to return a single
value, and can not be used with Multiple Query Matching.
Case 3: In order to capture a XML Fragment follow the below mentioned steps
a. Switch to Tree View.
b. Click on Server Response tab.

c. Manually browse through server response of find out the XML fragment to be
captured. In the below mentioned example we are required to capture the
entire EmployeeDetail.

d. Now right click on EmployeeDetail and select Save XML in parameter.

e. Provide the parameter name and click OK.

Following piece of code gets added and this captures the required data
lr_xml_extract("XML={response}",
"FastQuery=/Envelope/Body/EmployeeDetailResponse/EmployeDetailResult/diffgram/EmployeeDetailData/
EmployeeDetail",
"XMLFragmentParam=ParamXml_EmployeeDetail",
LAST);

NOTE : Values within the SOAP body are the variables which has to be either
parameterized or correlated.
5.3.2 Verification Point:
Case 1: Using LR in-built function (lr_xml_find) for response validation
lr_xml_find serves the same purpose as web_reg_find in Web(HTTP/HTML)
protocol.
a. Switch to Tree View.
b. Click on Server Response tab.
c. Manually browse through server response of find out the XML fragment to be
captured. In the below mentioned example we are required to capture the
entire EmployeeDetail.

d. Now right click on the value and select Insert XML check option.

e. If required you can check Ignore case and Continue on error and then click
OK

Following piece of code gets added and this does the necessary validation.
lr_xml_find("XML={response}",
"FastQuery=/Envelope/Body/UserDataResponse/UserDataResult/LoggedInUser/UserID",
"Value=12345",
LAST);

Code generated when Ignore case and Continue on error check box are selected
lr_xml_find("XML={response}",
"FastQuery=/Envelope/Body/UserDataResponse/UserDataResult/LoggedInUser/UserID",
"Value=12345",
"IgnoreCase=yes",
"NotFound=continue",
LAST);

Case 2: Customized code for validating the response.


char *position_1;
//strutr (String); converts "String" to upper case
//strstr(string1, string2);
//string1 - The string that is searched.
//string2 - The string that is searched for in the first string.
//strstr - returns the first occurrence of one string in another
/******Searches for LoginID in the server response. If found it's stored in "position"*****/
position_1 = (char *) strstr(lr_eval_string"{response}"
"),strupr(lr_eval_string("{Login_ID}")));

We need to place above code exactly below the Web Service request which has to be
validated. Here the value substituted for LoginID will be searched in response from the
server. We can also replace the {LoginID} with a hard coded value.
The following piece of code has to be placed at the end of the transaction.
/*****************************If match found transaction
PASSES**************************/
if(position_1!=NULL)
{
lr_end_transaction("GMS_A01_OpenGMSMain ", LR_PASS);
}
/*******************************Else the transaction
FAILS*******************************/
else
{
lr_end_transaction("GMS_A01_OpenGMSMain ", LR_FAIL);
}

You might also like