Sonoa

Using cURL for SOAP

How to issue a SOAP request (to Sonoa’s ServiceNet) using cURL from the command line:

shell command:

1
2
3
4
5
curl \
  -H "SOAPAction: urn:getCustomerDetails" \
  -H "Content-Type: text/xml" \
  -d "@getCustomerDetails.xml" \
  http://192.168.96.132:8080/samples/services/CustomerInfoService

where getCustomerDetails.xml is a file in the current directory.

getCustomerDetails.xml:

1
2
3
4
5
6
7
8
9
10
11
12
<soapenv:Envelope 
  xmlns:soapenv=
    "http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:cus=
    "http://www.sonoasystems.com/schemas-samples/2007/1/26/customer"> 
  <soapenv:Header/> 
  <soapenv:Body> 
    <cus:getCustomerDetails> 
      <cus:customerID>12</cus:customerID> 
    </cus:getCustomerDetails> 
  </soapenv:Body> 
</soapenv:Envelope>

shell output:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope 
    xmlns:soapenv=
      "http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Header />
  <soapenv:Body>
    <getCustomerDetailsResponse 
      xmlns=
        "http://www.sonoasystems.com/schemas-samples/2007/1/26/customer">
      <return>
        <customerID>12</customerID>
        <shipToAddress>
          <city>City 12</city>
          <country>USA</country>
          <name>Name 12</name>
          <state>CA</state>
          <street>Street 12</street>
          <zip>Zip 12</zip>
        </shipToAddress>
      </return>
    </getCustomerDetailsResponse>
  </soapenv:Body>
</soapenv:Envelope>

Reader Discussion

Fatiha

Tuesday November 17, 2009 at 8:03am

Thanks, it helps me a lot.

Fatiha

Jason Judge

Friday February 26, 2010 at 12:41pm

Thank you - that is a very handy technique.

I am using it to fetch jobs from a job site every hour in a simple shell script. PHP then reads and parses the XML. Doing this stage in the shell script is just a lot easier than in the PHP as it more easily copes with timeouts and does not have memory restrictions if the file happens to be very large.

soapUI is a great free tool for generating the SOAP action file from a WSDL very easily.

-- Jason

Comment on this post




Please enter the word you see in the image below:


Related posts

Sonoa

I am checking out Sonoa System’s ServiceNet product.

http://www.sonoasystems.com/

read more