How to do a SOAP wsdl web services call from the command line
I need to make a SOAP webservice call to https://sandbox.mediamind.com/Eyeblaster.MediaMind.API/V2/AuthenticationService.svc?wsdl and to use the operation ClientLogin while passing through the parameters: ApplicationKey, Password, and UserName. The response is UserSecurityToken. They are all strings.
Here is the link fully explaining what I am trying to do: https://sandbox.mediamind.com/Eyeblaster.MediaMind.API.Doc/?v=3
How can I do this on the command line? (Windows and/or Linux would be helpful)
It's a standard, ordinary SOAP web service. SSH has nothing to do here. I just called it with curl (one-liner):
$ curl -X POST -H "Content-Type: text/xml" \
-H 'SOAPAction: "http://api.eyeblaster.com/IAuthenticationService/ClientLogin"' \
--data-binary @request.xml \
https://sandbox.mediamind.com/Eyeblaster.MediaMind.API/V2/AuthenticationService.svc
Where request.xml
file has the following contents:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:api="http://api.eyeblaster.com/">
<soapenv:Header/>
<soapenv:Body>
<api:ClientLogin>
<api:username>user</api:username>
<api:password>password</api:password>
<api:applicationKey>key</api:applicationKey>
</api:ClientLogin>
</soapenv:Body>
</soapenv:Envelope>
I get this beautiful 500:
<?xml version="1.0"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<s:Fault>
<faultcode>s:Security.Authentication.UserPassIncorrect</faultcode>
<faultstring xml:lang="en-US">The username, password or application key is incorrect.</faultstring>
</s:Fault>
</s:Body>
</s:Envelope>
Have you tried soapui?
Read more
On linux command line, you can simply execute:
curl -H "Content-Type: text/xml; charset=utf-8" -H "SOAPAction:" -d @your_soap_request.xml -X POST https://ws.paymentech.net/PaymentechGateway
Here is another sample CURL - SOAP (WSDL) request for bank swift codes
Request
curl -X POST http://www.thomas-bayer.com/axis2/services/BLZService \
-H 'Content-Type: text/xml' \
-H 'SOAPAction: blz:getBank' \
-d '
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:blz="http://thomas-bayer.com/blz/">
<soapenv:Header/>
<soapenv:Body>
<blz:getBank>
<blz:blz>10020200</blz:blz>
</blz:getBank>
</soapenv:Body>
</soapenv:Envelope>'
Response
< HTTP/1.1 200 OK
< Server: Apache-Coyote/1.1
< Content-Type: text/xml;charset=UTF-8
< Date: Tue, 26 Mar 2019 08:14:59 GMT
< Content-Length: 395
<
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns1:getBankResponse
xmlns:ns1="http://thomas-bayer.com/blz/">
<ns1:details>
<ns1:bezeichnung>BHF-BANK</ns1:bezeichnung>
<ns1:bic>BHFBDEFF100</ns1:bic>
<ns1:ort>Berlin</ns1:ort>
<ns1:plz>10117</ns1:plz>
</ns1:details>
</ns1:getBankResponse>
</soapenv:Body>
</soapenv:Envelope>
Using CURL:
SOAP_USER='myusername'
PASSWORD='mypassword'
AUTHENTICATION="$SOAP_USER:$PASSWORD"
URL='http://mysoapserver:8080/meeting/aws'
SOAPFILE=getCurrentMeetingStatus.txt
TIMEOUT=5
CURL request:
curl --user "${AUTHENTICATION}" --header 'Content-Type: text/xml;charset=UTF-8' --data @"${SOAPFILE}" "${URL}" --connect-timeout $TIMEOUT
I use this to verify response:
http_code=$(curl --write-out "%{http_code}\n" --silent --user "${AUTHENTICATION}" --header 'Content-Type: text/xml;charset=UTF-8' --data @"${SOAPFILE}" "${URL}" --connect-timeout $TIMEOUT --output /dev/null)
if [[ $http_code -gt 400 ]]; # 400 and 500 Client and Server Error codes http://en.wikipedia.org/wiki/List_of_HTTP_status_codes
then
echo "Error: HTTP response ($http_code) getting URL: $URL"
echo "Please verify parameters/backend. Username: $SOAP_USER Password: $PASSWORD Press any key to continue..."
read entervalue || continue
fi
curl --header "Content-Type: text/xml;charset=UTF-8" --header "SOAPAction:ACTION_YOU_WANT_TO_CALL" --data @FILE_NAME URL_OF_THE_SERVICE
Above command was helpful for me
Example
curl --header "Content-Type: text/xml;charset=UTF-8" --header "SOAPAction:urn:GetVehicleLimitedInfo" --data @request.xml http://11.22.33.231:9080/VehicleInfoQueryService.asmx
More info