How To Use Soap Request In Postman
How to Use SOAP Request in Postman for API Testing
Postman is a popular tool for API testing, but it’s not just for REST APIs. You can also use Postman to test SOAP (Simple Object Access Protocol) APIs, which are commonly used in enterprise applications. This guide will walk you through using Postman to send SOAP requests and analyze the responses.
Setting Up a SOAP Request in Postman
-
Create a New Request: Open Postman and click on the “New” button to create a new request.
-
Select the HTTP Method: Choose “POST” as the HTTP method for sending SOAP requests.
-
Enter the SOAP Endpoint: In the “Request URL” field, paste the URL of the SOAP endpoint you want to test.
-
Set the Header:
- Content-Type: Set the “Content-Type” header to “text/xml”.
- SOAPAction: If your SOAP API requires a specific “SOAPAction” header, include it here. This header specifies the operation you’re performing.
-
Add the SOAP Body: In the “Body” tab, choose “raw” and select “XML” from the dropdown. Paste your SOAP request XML into the editor. Here’s a sample SOAP request for a simple “Hello World” service:
<?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> <HelloWorld xmlns="http://www.example.org/HelloWorld"> <name>World</name> </HelloWorld> </soapenv:Body></soapenv:Envelope>
- Send the Request: Click on the “Send” button to execute your SOAP request.
Analyzing the SOAP Response
Postman displays the response from the SOAP service. You’ll typically receive an XML response that contains the result of your request.
- Response Body: Review the XML response in the “Body” tab.
- Response Headers: Examine the response headers in the “Headers” tab for additional information, such as status codes and error messages.
- Validation: Use Postman’s built-in validation tools to ensure that the response matches your expectations.
- Schema Validation: You can validate the response against a predefined XML schema to ensure its structure and data types are correct.
- Assertions: Postman’s assertion library allows you to write custom validation rules using JavaScript.
How to Use SOAP Request in Postman - Practical Example
Scenario: Testing a SOAP service that retrieves weather information for a given city.
-
Find the SOAP Endpoint URL: The URL of the endpoint is typically provided in the API documentation. Let’s assume it’s
https://www.example.com/weather/service
. -
Get the SOAP Request Body: The API documentation or WSDL (Web Services Description Language) will specify the required XML structure for the request. Let’s assume the body needs to include the city name:
<?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> <GetWeather xmlns="http://www.example.org/weather"> <city>London</city> </GetWeather> </soapenv:Body></soapenv:Envelope>
-
Create the Postman Request:
- Method: POST
- URL:
https://www.example.com/weather/service
- Headers:
- Content-Type: text/xml
- SOAPAction: “GetWeather” (if required)
- Body: The XML code from step 2.
-
Send the Request: Click “Send.”
-
Analyze the Response: The response should contain weather information in XML format:
<?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> <GetWeatherResponse xmlns="http://www.example.org/weather"> <temperature>20</temperature> <conditions>Sunny</conditions> </GetWeatherResponse> </soapenv:Body></soapenv:Envelope>
- Validation: Use Postman’s validation tools to ensure that the temperature and conditions are in the expected format (numeric temperature, string conditions).
How to Use SOAP Request in Postman - WSDL (Web Services Description Language)
If the API provides a WSDL file, Postman can help you generate the SOAP request more easily.
- Import the WSDL: Go to “Import” in Postman, select “WSDL”, and paste the WSDL URL.
- Generate Request: Postman will create a request based on the WSDL information. You can modify the request based on your needs.
How to Use SOAP Request in Postman - Automating Testing
Postman’s collection feature allows you to automate SOAP testing:
- Create a Collection: Create a new collection in Postman for your SOAP API tests.
- Add Requests: Add the SOAP requests you want to automate to the collection.
- Add Assertions: Add validation rules using Postman’s assertion library.
- Run the Collection: Run the entire collection to execute your automated tests.
Conclusion
Postman is a powerful tool for testing SOAP APIs. Using Postman, you can send SOAP requests, analyze responses, and automate your testing to ensure the quality of your SOAP services.