Part 3 – How to Test a Web Service – Response and Requests

Joe Colantonio Web Services
PerfectoTopAd

How to Test a Web Service – Response and Requests

This is part 3 on out series of post on how to test a web service. To get up to speed make sure to also check out:

Part 1 – How to Test Web Service – How to Create a Web Service

Part 2 – How to Test a Web Service – Its all about the WSDL

Using a Web Service's  WSDL

Now that we have a working web service and understand a basic WSDL, let’s take a look at a web service’s request and response.

First, let’s import our WSDL into our test tool of choice. I will be using SOAPUI (a free open source tool), but you can use whatever tool you like.

In SoapUI, click on ‘File\New soupUI project'. In the New soapUI project, enter the Project Name: AddNums, and for Initial WSDL/WADL enter:

http://localhost/Webservice/DEMOAddNumbers.asmx?WSDL

SoapUI should import the “AddThis” method under projects AddNums\DEMOAddNumbersSOAP. Double clicking on the AddThis ‘Request 1’ will show the following:

*Remember — the WSDL should include all the info needed to interact with a web service. That’s why soapUi was able to read in the WSDL and automatically generate a request with the correct inputs for you.

Web Service Request/Response

Our DEMOAddNumbers web service is the most typical kind, in that a requester (in this case our test tool) sends a request to the service and waits.

The service then processes the request and sends a reply. Let’s see this in action:

For our request, let’s do a positive test by sending the service valid values:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
   <soapenv:Header/>
   <soapenv:Body>
      <tem:AddThis>
         <tem:x>5</tem:x>
         <tem:y>10</tem:y>
      </tem:AddThis>
   </soapenv:Body>
</soapenv:Envelope>

This is the response I get back when I send the request from SOAPUI:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <soap:Body>
      <AddThisResponse xmlns="http://tempuri.org/">
         <AddThisResult>15</AddThisResult>
      </AddThisResponse>
   </soap:Body>
</soap:Envelope>

What does SOAP have to do with Web Services

How does this communication take place? Basically, SOAP — which is a XML based protocol used for communicating with a Web Service — sends info to the request over HTTP. SOAP stands for Simple Object Access Protocol. If we look at our request, we will see soap elements such as SOAP Envelope, Header, and Body.
This is what a typical SOAP XML message contains.

SOAP Faults

For a Negative Test — if we send bad data in the request, a SoapFault should occur. So, if we send:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
   <soapenv:Header/>
   <soapenv:Body>
      <tem:AddThis>
         <tem:x>5</tem:x>
         <tem:y>10</tem:y>
      </tem:AddThis>
   </soapenv:Body>
</soapenv:Envelope>

We should get back a soapFault:


As we can see, the SOAP XML is the same as our previous response, but now it also contains a Fault element. A Fault element contains errors and status info.

Testing Web Services Wrap Up

And that’s my take on web services in a nutshell. For a deeper dive, I recommend checking out the site www3school.
I’ve also found SOA for the Business Developer: Concepts, BPEL, and SCA (Business Developers series)
to be a great resource book.

If you are using Unified Functional Testing also check out my latest Pluralsight video course

Quick Guide to API Testing with HP's Unified Functional Testing

21 comments
aanya - June 11, 2011

Hi Joe,
I am facing an error message as “The reason for the SOAP fault is: “System.Web.Services.Protocols.SoapException: Server was unable to read request. —> System.InvalidOperationException: There is an error in XML document (1, 22808). —> System.FormatException: The string ‘1955-03-01T00:00:00+00:00T00:00:00+01:00’ is not a valid AllXsd value.
at System.Xml.Schema.XsdDateTime..ctor(String text, XsdDateTimeFlags kinds)”

when I try to correlated the Soap request, but I am not able to find the exact reason for fault string.
Could you please help me..

Reply
    Joe Colantonio - June 11, 2011

    aanya » Hi – what web service is this for? Is this for the example web service I created in my post? If so I’m not sure how this error could occur for my example. I’ve never seen this error before but it look like you are passing an invalid date or time value to the service (The string ‘1955-03-01T00:00:00+00:00T00:00:00+01:00’). If this is not my web service then take a look at the specifications for your web service to find out what the correct date format should be to use.

    Reply
aanya - June 19, 2011

Hi Joe,

Sorry for late reply. Thanks for assisting me you really saved me by guiding me. :)

Reply
aanya - June 19, 2011

Hi joe,

I need your guidance once again. I am facing an error as: Error: The reason for the SOAP fault is: “System.Web.Services.Protocols.SoapException: Server was unable to read request. —> System.InvalidOperationException: There is an error in XML document (1, 32500). —> System.Data.ConstraintException: Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.

I am not able to get the source of this error… Could you please help me to sort out..!! I know this is totally out of context from your above examples, but After spending two consecutive days on this issue I am not able to find answer and any person who could help me to get it straight. :(

Reply
Nitin - May 9, 2012

Hey Joe,

Does QTP support WADL.

Reply
Rama - May 29, 2013

Hi Joe,

Am having trouble with SOAP attachments. ST does not seem to recognize it when getting the SOAP response. The response attachment type is MIME.

It works with SOAPUI and not on ST. Can you please help me on this?

Reply
    Joe Colantonio - September 2, 2013

    Hi Ram – sorry for my late response – did you resolve this? I been trying to find a way to reproduce this but have not been successful.

    Reply
Carol - July 9, 2013

Hello Joe,

Can we install SOAPUI under Fedora15?

Reply
    Joe Colantonio - July 17, 2013

    Hi Carol I know that in general soapUI does support Linux and it list Fedora as one of the supported distributions. I can’t find anywhere on their site that list what exact versions are supported. Are you having issue with Fedora 15?

    Reply
Rico - August 29, 2013

Greetings, I’ve found your tutorials to be very insightful and helping. I have been looking for a guide to test WSDL with HP Stress Test and input parameters such as token and username for the service, but I am not sure if it is discussed already.

Reply
    Joe Colantonio - September 2, 2013

    Hi Rico – thanks glad you like my blog :) what tool is HP Stress tests ( LoadRunner??)

    Reply
      Rico - September 11, 2013

      Sorry, my mistake. It is HP Service Test. I am looking a way to test WSDL with custom inputs.
      Is it possible to simulate multiple concurrent sessions to test the methods of the WSDL methods?

      Reply
Rutvi - July 15, 2014

Hiee joe,

I have a array of element populated in response XML of Request 1, and I want to take a particular array element from the complete array in XML Request 2.

Can you guide me how it is possible.

Reply
saikrishna - October 15, 2014

how to validate xml against multiple xsds in hp service test

Reply
Rajesh Kuchana - May 29, 2015

How to test rest services in loadrunner and how we can verify response with request,please help me in this once we are unable to find the solution in search

Reply
Bimal - October 19, 2016

I am having issue with reading data that comes as a MIME attachment. e.g. if I like to compare output field with the data in the excel data sheet, I need to read the output first and then compare. But when it returns as an attachment ( start s and ends with MIMEBoundry….) it seems unable to read.

Anyone experienced this issue and solved? Any help is appreciated.

Reply
Nilton de Araújo - February 22, 2017

Hi, if you can help me, my methods do not return the request file

Reply
Click here to add a comment

Leave a comment: