30 June, 2016

How to test web service using command line curl

How to test web service using command line curl.


How to test web service using command line curl, is a very often requirement.

This is always very easy to call the web service via a java client,  but sometimes we need to call the service using curl.

One thing you know ? its really very tactical to  call the web service from terminal/command line using curl command.


I have  steps with sample example :-


You need to know the below things before calling the service via curl.

Service Endpoint - The web service endpoint you want to call.

Example - http://myserverip.mycorpnet.com.au:16500/NaaSAutomation/NaaSManageService

Operation Name - The operation name , you want to execute.

Example - readProviderRequest

SoapAction - The soap action defined in WSDL.

Example - SOAPAction:/NaaSAutomation/Resources/WSDLs/ESB/Service/NaaSManageService-service0.serviceagent/NaaSManageServicePortEndpoint0/ManageProviderRead

Create sample valid request xml for sending to the service.

Request.xml
------------------

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:dto="http://dto.service.myservice.networkservice.test.service.mycorp.com.au/">
   <soapenv:Header/>
   <soapenv:Body>
      <dto:readProviderRequest>
         <callerIdentity>myIdentity</callerIdentity>
         <dto:ProviderName>JDevelopersGuide</dto:ProviderName>
      </dto:readProviderRequest>
   </soapenv:Body>
</soapenv:Envelope>



Curl Command :-

curl --header "Content-Type: text/xml;charset=UTF-8" --header "SOAPAction:/NaaSAutomation/Resources/WSDLs/ESB/Service/NaaSManageService-service0.serviceagent/NaaSManageServicePortEndpoint0/ManageProviderRead" --data @Request.xml http://myserverip.mycorpnet.com.au:16500/NaaSAutomation/NaaSManageService



Response got from Curl :-



<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Body>
      <ns0:ManageProviderCreateRes xmlns:ns0="http://www.mycorpnet.com.au/NaaSAutomation/Resources/Schemas/CreateRequest.xsd">
         <ns0:response>
            <ns0:providerName>JDevelopersGuide</ns0:providerName>
            <ns0:createStatus>SUCCESS</ns0:createStatus>
            <ns0:rollbackInitiated>TRUE</ns0:rollbackInitiated>
         </ns0:response>
      </ns0:ManageProviderCreateRes>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>



Hope it will help you.
Follow for more details on Google+ and @Facebook!!!

Find More :-

No comments:

Post a Comment