Thursday, September 20, 2012

Calling Web Service with wget

Wget - "The non-interactive network downloader." (from the man page) could be used to call web service if a request XML is available. This is useful to quickly test a web service.
1. First step is to capture the SOAP request in XML format. Wireshark could be used for this. Below is a sample of a request which is used to test the failover setup for application server connection when RAC is used. The request will send the client's machine name as the input and will respond with the instance connected at the back end.
<?xml version='1.0' encoding='UTF-8'?>
  <S:Envelope xmlns:S="">
      <ns2:getAppAndDBServerNames xmlns:ns2="http://asanga/">
2. Save the XML request in a file. This file will be used as the input to the wget.
3. Execute the wget command as shown below
wget --post-file=input.xml 
--header="Content-Type: text/xml" --output-document=soapResponse.xml
input.xml is the file with xml request created in step 2 above. Response from the WS will be saved into soapResponse.xml. is the IP and port of the server where web service is deployed and /FailOverTest/FailOverTestPort is the service called.
$ wget --post-file=input.xml --header="Content-Type: text/xml" --output-document=soapResponse.xml
--2012-09-20 11:47:08--
Connecting to connected.
HTTP request sent, awaiting response... 200 OK
Length: 331 [text/xml]
Saving to: `soapResponse.xml'

100%[============================================================================================================>] 331         --.-K/s   in 0s

2012-09-20 11:47:08 (35.1 MB/s) - `soapResponse.xml' saved [331/331]
4. The soapResponse.xml will have the output in XML format.
<?xml version="1.0" ?>
      <ns2:getAppAndDBServerNamesResponse xmlns:ns2="http://asanga/">
          Connected to ent11g2 DB Server Application Server on Thu Sep 20 11:34:02 BST 2012