Hellow there folks! These days most of the web services are exposed as REST or SOAP. There could be a chance where you need to make a request from your command line rather than installing a tool such SOAPUI. Tools are really helpful but there are times where you can’t use tools. I’ll be using curl to make the request. if you don’t know about curl it can transfer data using various protocols. If you don’t have curl installed use the below command.
sudo apt-get install curl
SOAP Request Flow
Step 1
Let’s create a SOAP envelope as below which is the SOAP request to be sent via curl. Create a file with the below content named “request.xml”. The SOAP envelope and the SOAP request parameters depend on your web service.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://schemas.conversesolutions.com/xsd/dmticta/v1"> <soapenv:Header/> <soapenv:Body> <v1:GetVehicleLimitedInfo> <v1:vehicleNo>?</v1:vehicleNo> <v1:phoneNo>?</v1:phoneNo> </v1:GetVehicleLimitedInfo> </soapenv:Body> </soapenv:Envelope>
Step 2
Let’s make a request using the curl command.
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
Below mentioned should be replaced according to your web service.
- ACTION_YOU_WANT_TO_CALL
- FILE_NAME
- URL_OF_THE_SOAP_WEB_SERVICE_ENDPOINT
See the example below to get an idea.
curl --header "Content-Type: text/xml;charset=UTF-8" --header "SOAPAction:urn:GetVehicleLimitedInfo" --data @request.xml http://11.22.33.231:9080/VehicleInfoQueryService.asmx
See the sample O/P below. You should get a similar O/P according to your web service.
Example O/P
<?xml version="1.0" encoding="UTF-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soap:Body> <GetVehicleLimitedInfoResponse xmlns="http://schemas.conversesolutions.com/xsd/dmticta/v1"> <return> <ResponseMessage xsi:nil="true" /> <ErrorCode xsi:nil="true" /> <RequestId>1411050004</RequestId> <TransactionCharge>200</TransactionCharge> <VehicleNumber>GP-XXYY</VehicleNumber> <AbsoluteOwner /> <EngineNo>4G13-YX59ZC</EngineNo> <ClassOfVehicle>MOTOR CAR</ClassOfVehicle> <Make>MITSUBISHI</Make> <Model>LANCER</Model> <YearOfManufacture>1999</YearOfManufacture> <NoOfSpecialConditions>0</NoOfSpecialConditions> <SpecialConditions xsi:nil="true" /> </return> </GetVehicleLimitedInfoResponse> </soap:Body> </soap:Envelope>
Hope you got an idea how to make a request SOAP request using command line. If you have any questions let me know in the comments below. Your feedback is highly appreciated(happy-face).
That was the quickest and most effective way to learn how to send SOAP request via cURL.
Thanks!
Thanks much for the information.
how can we send the user authentication info in a script using CURL? i would like to mask the password file as well.
If I understand your question right, what you can do is you can send the file as an attachment as shown below.
First, thanks for share this article, helps much!
So, can I use the authentication on request.xml file?
Thanks, very helpful.
Great :-)
Hi
When I tried this:
{quote}
/opt/freeware/bin/curl -H “Content-Type: text/xml; charset=utf-8” -H “SOAPAction:urn:test” -d @$f -X POST http://127.0.0.1:9080/services/testServices
{quote}
I got the following error:
{quote}
You can only select one HTTP request!
{quote}
How can solve this problem??
thanks in advance
Tiago
Try these two links
http://stackoverflow.com/questions/286982/curl-post-data-and-headers-only
http://stackoverflow.com/questions/12667797/using-curl-to-upload-post-data-with-files
Pingback: Using Curl | RaSor's Tech Blog
Superb. I was able to adapt it to SOAP messages we use for testing and it worked. Thanks so much. :)
I’m glad I could help :-)
How do I call a SOAP function using curl?
I have a problem. http://stackoverflow.com/questions/30612167/passing-plaintext-data-as-string-to-invoke-soap-method-in-php, But I don’t know how to start using cURL. please help.
There are a lot articles written on the particular subject. Please Google
Thanks for the help! Is very usefull!
I’m glad I could help :-)
I have an error:
soap:ClientUnmarshalling Error: java.lang.IllegalArgumentException:
Try the link below.
http://stackoverflow.com/questions/657091/jaxb-gives-me-java-lang-illegalargumentexception-is-parameter-must-not-be-null
exactly what I needed with no fluff. very clear. I was able to automate SOAP calls from Jenkins with this in minutes after struggling prior. Thanks!
Good to know :-)
Hello I am trying to access BMC Remedy Webservices by using this method but it does not work, althougth it has work with other web services and BMC Remedy’s Web service works with a SOA Client UI. When I Invoke the WS using curl it returns java.lang.null.pointer.exception. the same XML input is working on the SOA Client. Any Ideas about what might be wrong?
Hello, what if the “SoapAction” is Soapction=”” in the wsdl file?
You must escape the ” character like this ”
“SoapAction=”””
Pingback: Let’s make a SOAP request from command line(curl)? – Dasun Hegoda – 小亮 (Oscar) 書籤
I searched all around the net for a solution of SOAP using Node JS (because need SOAP service to set up data on Protractor) and my brain went fried as I could not use any examples. Now wanting to use Jenkins to call SOAP before running Protractor and seeing this post solution work with my WSDL is a definite joy! Thanks soooo much!
Sir how to send XML object that is not in file to server using c++ cpr.
Please give me the example send function syntax.Thanks in advance.Please give me reply.
hi,we provide online training & video tutorial for soapui
for free videos refer
http://soapui-tutorial.com/soapui-tutorial/introduction-to-webservices/
I am posting below soap xml
curl -X POST –header “Content-Typ_SERVICE_ENDPOINT” -d –data-urlencode ‘xmlRequest=Make My TripSrinu Muppananon-refundable booking’ http://testuzz.cultuzz.com:8080/cultagent/services/GetResService/processMakeMyTripRQ -v
I got below example
org.apache.axis2.AxisFault: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character ‘-‘ (code 45) in prolog; expected ‘<‘
at [row,col {unknown-source}]: [1,1]
at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:175)
at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:142)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)
Could please help for find out the problem
I’m also trying the same thing. I wanted to send soap request xml as an argument rather than reading from the file. Did you find any solution to this?
im trying to find the same, please help me with that
Pingback: SOAP calls from python [links] – dbarenas
Really love this article. Let me repost on my blog for my own documentation.
Pingback: REPOST : Let’s make a SOAP request from command line (curl)? – @ykzir
if you need curl with basic auth add `–user login:pass` to args
Thank you for sharing.
Helped me a lot in debugging an issue.
Right now I am trying to call a Web service using Curl command from Unix platform. The Web service is available on external server. I can connect the external server using telnet only. The Web service uses basis authentication and I have to provide a username and password.
Can anyone please help me with correct way to execute this ?
This has been the clearest example of SOAP cURL calls. Thank you very much!
this honestly probably is a very very useful description; however, I feel like I am trying to learn Chinese. I know very little about coding and i am trying to set up a diction command that will run a web service that will play a YouTube video. help
I get this error
curl: (6) Could not resolve host: request.xml
How get response to file
Hello
You’re great !
Thanks a lot
Christophe