Tuesday, July 24, 2012

How to invoke a Web service using curl

To invoke a Web service using curl you basically just need to post the soap envelope and the required soap action. I needed to invoke a Web service from cron so I wrote this script to do it using this method:

#!/bin/bash
LOG_FILE="/var/log/armcron.log"
echo "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:arm=\"http://www.com.co.za/ARM/\">
   <soapenv:Header/>
   <soapenv:Body>
      <arm:warnForEndDate/>
   </soapenv:Body>
</soapenv:Envelope>" > /tmp/warnForEndDate
echo "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:arm=\"http://www.com.co.za/ARM/\">
   <soapenv:Header/>
   <soapenv:Body>
      <arm:revokeForEndDate/>
   </soapenv:Body>
</soapenv:Envelope>" > /tmp/revokeForEndDate

curl -H 'SOAPAction: "http://www.com.co.za/ARM/warnForEndDate"' -X POST -H 'Content-Type: text/xml;charset=UTF-8' -d @/tmp/
revokeForEndDate http://localhost:8080/armws/services/ARM/ >> $LOG_FILE 2>&1

No comments:

Followers