Calling SOAP API from UNIX Shell

Posted on May 14, 2007 by ZDima.
Categories: UNIX-Shell.

Sometime a UNIX shell is a best choice to have a quick clean solution. However sometimes it is luck the flexibility and APIs to work with latest technologies.

Recently I was asked to write a small UNIX application and one of the requirements was to update MS SQL database table with status value. i didn’t want to install additional packages on UNIX server to achieve direct access to MS SQL server, but rather to use a minimal tools.

I decided to use SOAP as a transport layer between UNIX and MS SQL server. On UNIX machine I install wget. Make sure you install wget with at least version 1.10.2!!!

On Windows machine I create a simple Web Service application using ASP.NET that will access the database using native driver.

Now, to send a request I will create an XML file with SOAP envelop:

cat > $RQXML <<End
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
 xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <SetStatus xmlns="http://domain.com/">
      <FormID>${FORM_ID}</FormID>
      <Status>${ITEM}</Status>
    </SetStatus>
  </soap12:Body>
</soap12:Envelope>
End

Then we will send request to web service using wget:

if ! /usr/local/bin/wget -q -O $OUTPUT --post-file=$RQXML
       --header="Content-Type: text/xml; charset=utf-8" ${URL}
then
  # failre here
  return 0
fi

The important part of this line is —-header=”Content-Type: text/xml; charset=utf-8″. It will indicate that the stream is an XML data. The reply from server will be stored into ${OUTPUT} which you can parse later for results.

no comments yet.

Leave a comment

Names and email addresses are required (email addresses aren't displayed), url's are optional.

Comments may contain the following xhtml tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>