Let's make a SOAP request from command line(curl)?
Hellow there folks! These days most of the web services are exposed as RESTor 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 curlit 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
Image Courtesy : java-forums.orgStep 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).