How To Call Soap Web Service Using Postman
Calling SOAP Web Services with Postman
Postman, a popular tool for API testing, can be used to effectively interact with SOAP web services. This guide will walk you through the process of setting up and executing SOAP requests using Postman.
Understanding SOAP and Its Structure
SOAP (Simple Object Access Protocol) is a messaging protocol used to exchange data between applications. It defines a structured format for transmitting XML messages, ensuring interoperability between disparate systems. A SOAP message consists of the following parts:
- Envelope: The outermost element, containing the entire message.
- Header: Optional section for metadata, like security credentials.
- Body: Contains the actual data being transmitted.
Setting Up Postman for SOAP Requests
- Install Postman: If you haven’t already, download and install Postman from https://www.postman.com/.
- Create a New Request: Open Postman and click on “New” to create a new request.
- Select HTTP Method: For SOAP requests, you typically use the POST method.
- Set Request URL: Enter the URL of your SOAP web service endpoint.
Sending a SOAP Request
- Choose the “Body” Tab: In the Postman interface, switch to the “Body” tab.
- Select “Raw” and “XML”: Choose “Raw” as the body type, and set the content type to “XML.”
- Paste the SOAP XML: Paste your SOAP request XML code into the “Raw” body field.
Example:
<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soapenv:Body> <GetWeatherData xmlns="http://www.example.com/weather"> <City>London</City> </GetWeatherData> </soapenv:Body></soapenv:Envelope>
- Add Headers: For SOAP requests, you typically need to add headers:
- Content-Type: “application/soap+xml”
- SOAPAction: “http://www.example.com/weather/GetWeatherData”
Note: The SOAPAction
header indicates the specific operation being requested from the web service.
- Send the Request: Click the “Send” button to execute your SOAP request.
Receiving the SOAP Response
Once you send the request, Postman will display the SOAP response in the “Body” tab. The response will be in XML format.
Example Response:
<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soapenv:Body> <GetWeatherDataResponse xmlns="http://www.example.com/weather"> <CurrentTemperature>15</CurrentTemperature> <Condition>Partly Cloudy</Condition> </GetWeatherDataResponse> </soapenv:Body></soapenv:Envelope>
Working with SOAP Envelopes and Operations
- Generate SOAP Envelopes: Utilize tools like online SOAP request builders, or create your own XML structures based on the web service’s WSDL (Web Services Description Language) definition. The WSDL document outlines available operations, data types, and request/response formats.
- Identify Target Operations: Consult the WSDL to determine the specific SOAP operation you need to invoke within your SOAP request. Each operation corresponds to a specific service function.
Example:
Assuming your WSDL defines a GetWeatherData
operation, the XML structure within the SOAP body should be:
<GetWeatherData xmlns="http://www.example.com/weather"> <City>London</City></GetWeatherData>
Note: The <GetWeatherData>
tag will be unique for each operation and should align with the WSDL definition.
Using Postman for SOAP Testing
Postman can facilitate robust SOAP testing by:
- Automated Request Execution: Schedule automated runs to ensure consistent service performance.
- Response Verification: Validate the response’s correctness and content, checking for expected data and status codes.
- Assertion Creation: Use Postman’s assertion capabilities to automate the verification of SOAP responses.
- Collaboration and Documentation: Share test suites and results with your team, enhancing communication and knowledge sharing.
Example Assertion:
pm.test("Verify temperature is present", function () { pm.response.to.have.body("CurrentTemperature");});
Conclusion
Postman is a powerful tool for working with SOAP web services, enabling you to easily send, receive, and test your web service interactions. By following the steps outlined in this guide, you can leverage the versatility of Postman for all your SOAP-related tasks.