I am new to SOAP and xml. I read a number of tutorials but nothing seems to be clear enough.
I am abit confused, Just how does one send an SOAP request? The way I have tried to do this is by saving my SOAP request (as seen below) as: testRequest.xml.
POST /MobileCashPayout.asmx HTTP/1.1
Host: 192.168.1.80
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?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>
<Payout xmlns="http://www.mycel.com/">
<Username>string</Username>
<Password>string</Password>
<referenceID>string</referenceID>
<sourceMsisdn>string</sourceMsisdn>
<destMsisdn>string</destMsisdn>
<Amount>decimal</Amount>
<MobilePin>string</MobilePin>
<cashInformation>string</cashInformation>
<merchantName>string</merchantName>
</Payout>
</soap12:Body>
</soap12:Envelope>
I then open the file (testRequest.xml) with a browser in order for it to be sent..
what I get in return is an error message stating:
XML Parsing Error: syntax error
Location: localhost/projects/test.xml
Line Number 1, Column 1:POST /MobileCashPayout.asmx HTTP/1.1
^
Am I sending it the wrong way?
Please help me out?
Opening this document in browser wouldn't send a request. You have several options:
- write a little script in any familiar language, script should connect to specified server and send a POST request with a body as mentioned in your message
- use some of existing programs to do that for you
If you're inexperienced I would definitely recommend second option. My personal favourite is SoapUI, see here.
This blog post helped me.
Python SOAP Request using Requests
#!/usr/bin/env python
# encoding: utf-8
import requests
from XML import XML
request = u"""<?xml version="1.0" encoding="utf-8"?>
<soapenv:envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://www.webserviceX.NET/">
<soapenv:header>
<soapenv:body>
<web:conversionrate>
<web:fromcurrency>GBP</web:fromcurrency>
<web:tocurrency>CHF</web:tocurrency>
</web:conversionrate>
</soapenv:body>
</soapenv:header></soapenv:envelope>"""
encoded_request = request.encode('utf-8')
headers = {"Host": "www.webservicex.net",
"Content-Type": "text/xml; charset=UTF-8",
"Content-Length": len(encoded_request)}
response = requests.post(url="http://www.webservicex.net/CurrencyConvertor.asmx",
headers = headers,
data = encoded_request,
verify=False)
print unicode(XML(response.text))
On linux you can use curl
to send the soap xml. Here's how to do it:
curl --header "Content-Type: text/xml;charset=UTF-8" --header "SOAPAction: ACTION_YOU_WANT_TO_CALL" --data @FILE_NAME URL_OF_THE_SOAP_WEB_SERVICE_ENDPOINT
Using the testRequest.xml
file created you can
curl --header "Content-Type: text/xml;charset=UTF-8" --header "SOAPAction: ACTION_YOU_WANT_TO_CALL" --data @testRequest.xml URL_OF_THE_SOAP_WEB_SERVICE_ENDPOINT
Here is a link that describes the full process.
You cannot send a soap request when a browser as far as I know.
I propose you use a tool like Soap UI
to send a request.