Tuesday, June 15, 2010

Testing Webservices outside Siebel / Testing Inbound Siebel Webservices - using WGET

I am a Siebel EAI developer. But sometimes I feel that Siebel does not provide the freedom to properly play around with webservice settings, or to test them properly. In most projects, we use a third party tool like SOAP UI or XML SPY to test inbound Siebel webservices. Sometimes when an outbound webservice call from Siebel fails, we try to reproduce the error from SOAP UI to try and find out if there is something wrong in the Siebel configuration. While most developers love the fact that SOAP UI is free and can consume  WSDLS and generate SOAP files, I find it terribly slow. Also, when working on client machines via an RDP/MSTSC connection, I need quick results and cannot wait for SOAP UIs resource hungry interface to load up. Altova XML Spy is faster, but its not free.

 

I set out to find another way to test webservices without using and costly or resource hungry tool. And I found a solution on Unix.

 

Unix developers are well aware of and have been using a command called wget to test http and soap interfaces. Wget is a powerful unix command which can be used to download content, post Http requests, and now even SOAP requests, as I found out. If you have a valid SOAP request, all you need is to send it across to a webservice/url, you can use Wget to do this.  This command has been ported to windows here.I have been using this trick for months now, and it has saved me looaadss of time.

 

Essentially, a SOAP request contains 3 parts

 

·         SOAP Header

·         SOAP Body

·         RAW Parameters / SOAP Parameters

 

The  SOAP Header and Body is as name suggests, contains schema information and data. The SOAP parameters contains additional info as to which url is to be hit and what is the format. Also there is one parameter for length, which contains the length of the soap message (header + body) in char counts. So, the length of the soap message has to be sent.

 

At Siebelunleashed, Neel explains how to trigger outbound webservice from Siebel. I will explain how to do the same thing from outside Siebel.  The example here again uses the GeoIPservice.

 

If you go this link, you will see the actual SOAP request for the service.

 

POST /geoipservice.asmx HTTP/1.1

Host: www.webservicex.net

Content-Type: text/xml; charset=utf-8

Content-Length: length

SOAPAction: "http://www.webservicex.net/GetGeoIP"

 

<?xml version="1.0" encoding="utf-8"?>

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

  <soap:Body>

    <GetGeoIP xmlns="http://www.webservicex.net">

      <IPAddress>string</IPAddress>

    </GetGeoIP>

  </soap:Body>

</soap:Envelope>

 

Here, the section in blue is the SOAP/RAW parameter section. And the length highlighted in bold has to contain the length of the soap request. After we frame this entire request, we have to send it across as an HTTP request.

 

Here is what we do.

 

1.     Create a folder on your desktop. Download wget for windows. Don’t worry, its free and safe J

2.     Create three files in your folder

·         Req.xml -  this will contain the soap message

·         url.txt – this will contain the url

·         send.bat – we will automate this in a bat file.

3.     Open up req.xml in notepad and enter this.

 

<?xml version="1.0" encoding="utf-8"?>

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

  <soap:Body>

    <GetGeoIP xmlns="http://www.webservicex.net">

      <IPAddress>216.239.51.99</IPAddress>

    </GetGeoIP>

  </soap:Body>

</soap:Envelope>

 

The ip here is that of Google. We shall see where google’s servers are located.

 

4.      Open up url.txt and enter this

 

http://www.webservicex.net/geoipservice.asmx

 

You will get this address from the WSDL. Open up the WSDL and look for a section called http:address

 

<wsdl:port name="GeoIPServiceHttpPost" binding="tns:GeoIPServiceHttpPost">

  <http:address location="http://www.webservicex.net/geoipservice.asmx" />

 

 

5.     Open up the send.bat file in notepad and enter this

wget  --input-file=url.txt   -nv --post-file=req.xml  --output-document=resp.xml   --header="Content-Type: text/xml" --header="SOAPAction: "http://www.webservicex.net/GetGeoIP"

 

notepad resp.xml

 

6.     Your folder should now contain 4 files. Execute send.bat, either by double clicking or from run command.

 

In a moment, the SOAP request will be sent across and the response should open up in notepad.

 

<?xml version="1.0" encoding="utf-8"?><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><GetGeoIPResponse xmlns="http://www.webservicex.net"><GetGeoIPResult><ReturnCode>1</ReturnCode><IP>216.239.51.99</IP><ReturnCodeDetails>Record Found</ReturnCodeDetails><CountryName>UNITED STATES</CountryName><CountryCode>US</CountryCode></GetGeoIPResult></GetGeoIPResponse></soap:Body></soap:Envelope>

 

 

The response shows us that the 216.239.51.99  is in UNITED STATES.

 

When we run the bat file, wget takes the req.xml file and adds the header parameters we specified.

 

wget  --input-file=url.txt   -nv --post-file=req.xml  --output-document=resp.xml   --header="Content-Type: text/xml" --header="SOAPAction: "http://www.webservicex.net/GetGeoIP"

 

Here the parameters are Content-Type and SOAPAction. Inaddition, WGET also adds the content length required for the request.  WGET provides a debug option to see the complete request going out. Just add –debug in the beginning like this

 

wget  --debug --input-file=url.txt   -nv --post-file=req.xml  --output-document=resp.xml   --header="Content-Type: text/xml" --header="SOAPAction: "http://www.webservicex.net/GetGeoIP"

 

You will see the response with debug information like this.

 

C:\test>wget  --debug --input-file=url.

txt   -nv --post-file=req.xml  --output-document=resp.xml   --header="Content-Ty

pe: text/xml" --header="SOAPAction: "http://www.webservicex.net/GetGeoIP"

Setting --input-file (input) to url.txt

Setting --no (verbose) to 0

Setting --post-file (postfile) to req.xml

Setting --output-document (outputdocument) to resp.xml

Setting --header (header) to Content-Type: text/xml

Setting --header (header) to SOAPAction: http://www.webservicex.net/GetGeoIP

DEBUG output created by Wget 1.11.4 on Windows-MSVC.

 

Loaded url.txt (size 44).

seconds 0.00, Caching www.webservicex.net => 209.162.186.60

seconds 0.00, Created socket 1932.

Releasing 0x00985058 (new refcount 1).

 

---request begin---

POST /geoipservice.asmx HTTP/1.0

User-Agent: Wget/1.11.4

Accept: */*

Host: www.webservicex.net

Connection: Keep-Alive

Content-Type: text/xml

Content-Length: 370

SOAPAction: http://www.webservicex.net/GetGeoIP

 

---request end---

[writing POST file req.xml ... done]

 

---response begin---

HTTP/1.1 200 OK

Connection: keep-alive

Date: Tue, 15 Jun 2010 08:12:10 GMT

Server: Microsoft-IIS/6.0

X-Powered-By: ASP.NET

X-AspNet-Version: 2.0.50727

Cache-Control: private, max-age=0

Content-Type: text/xml; charset=utf-8

Content-Length: 519

 

---response end---

Registered socket 1932 for persistent reuse.

2010-06-15 01:12:10 URL:http://www.webservicex.net/geoipservice.asmx [519/519] -

> "resp.xml" [1]

FINISHED --2010-06-15 01:12:10--

Downloaded: 1 files, 519 in 0s (2320 GB/s)

 

C:\test>notepad resp.xml

           

      Notice the content length (370) added by WGET.

 

 

 

Conclusion : WGET is a powerful tool which can be used to test webservices without using tools like SOAP UI or XML SPY. In fact, this is exactly what SOAP UI does, but in a more fancy way. Similarily, WGET can also be used to test inbound Siebel webservices.

 

 

I discovered WGET it only because I wanted a quick and efficient way to testing webservices on windows as well as unix. Now I can test webservices without installing shareware or when I don’t have admin rights to install them. Hope this helps Siebel and non Siebel developers in their work.

 

 

May the source be with you.

3 comments:

  1. Great Post man ths piece of information is very useful

    ReplyDelete
  2. curl -H "Content-Type: text/xml; charset=utf-8" -H "SOAPAction:http://www.webserviceX.NET/GetWeather" -d@soap-request.xml http://www.webservicex.net/globalweather.asmx > output.xml

    wget --input-file=url.txt -nv --post-file=soap-request.xml --output-document=resp.xml --header="Content-Type: text/xml" --header="SOAPAction:http://www.webserviceX.NET/GetWeather"

    PC - ~ # cat soap-request.xml




    Tampa
    United States




    PC - ~ # cat url.txt
    http://www.webservicex.net/globalweather.asmx

    ReplyDelete
  3. Hi you missed one " in the wget calling on step 5

    wget --input-file=url.txt -nv --post-file=req.xml --output-document=resp.xml --header="Content-Type: text/xml" --header="SOAPAction: "http://www.webservicex.net/GetGeoIP""

    Good tutorial, thanks, solved my problem

    ReplyDelete