Skip to content

How To Use Postman For Soap Request

API Testing Blog

Mastering SOAP Requests with Postman: A Comprehensive Guide

Postman, the renowned API testing platform, is not just for REST APIs. It’s also a powerful tool for interacting with SOAP services. This guide will walk you through the process of sending SOAP requests in Postman, covering the essential steps and practical examples.

1. Understanding SOAP and its Structure

SOAP (Simple Object Access Protocol) is a messaging protocol built on XML. It defines a standardized way of exchanging structured information between applications, often over HTTP.

A typical SOAP message consists of:

  • Envelope: The outer container that houses all other elements.
  • Header: Optional section containing metadata, like authentication information.
  • Body: Contains the actual data or service request.

2. Setting Up the Postman Workspace

To start using Postman for SOAP requests, you’ll need to create a workspace or a collection where you can organize your requests and manage your test data.

  • Create a Workspace: If you don’t have one already, create a new workspace in Postman. This helps keep your projects organized.
  • Create a Collection: Within your workspace, create a new collection for your SOAP requests. This will group related requests together.

3. Creating a New SOAP Request

Step 1: Choose the Request Type: In Postman, select “POST” as the HTTP method, as SOAP requests are typically sent using the POST method.

Step 2: Specify the URL: Enter the endpoint URL of your SOAP service in the “Request URL” field. This URL will be the address of the web service you want to interact with.

Step 3: Select the “Body” Tab: From the options, choose “raw” and select “XML” as the content type. This will allow you to write your SOAP request in XML format.

Step 4: Construct the SOAP Envelope: Paste the following sample SOAP request code into the “raw” field:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<tem:HelloWorld/>
</soapenv:Body>
</soapenv:Envelope>

Explanation:

  • <soapenv:Envelope>: This is the root element of the SOAP message.
  • xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/": This defines the namespace for the SOAP envelope.
  • xmlns:tem="http://tempuri.org/": This defines the namespace for the target service (replace “http://tempuri.org/” with the actual namespace of your service).
  • <soapenv:Header>: This section is empty in this example, but it can contain authentication or other metadata.
  • <soapenv:Body>: This is where the actual service request is placed.
  • <tem:HelloWorld/>: This is the specific operation you want to invoke.

4. Sending and Interpreting the Response

After you’ve constructed your SOAP request, click the “Send” button in Postman. The response from the SOAP server will be displayed in the response pane.

  • Inspect the Response: Look for the <soapenv:Body> section of the response. This will contain the data returned by the SOAP service.

Sample Response:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<tem:HelloWorldResponse xmlns:tem="http://tempuri.org/">
<tem:HelloWorldResult>Hello, World!</tem:HelloWorldResult>
</tem:HelloWorldResponse>
</soapenv:Body>
</soapenv:Envelope>

5. Using Environment Variables for Flexibility

Environment variables in Postman are valuable for creating reusable and flexible SOAP requests. You can define variables for URLs, namespaces, and other parameters to easily modify your requests.

Step 1: Create an Environment: Click on the “Manage Environments” button in Postman to create a new environment.

Step 2: Add Variables: Define variables with names like soapEndpoint, soapNamespace, etc. Assign appropriate values to these variables.

Step 3: Use Variables in Your Request: Use the {{ }} syntax to reference your environment variables within the request. For example, replace the hardcoded URL with {{soapEndpoint}}.

6. Example: Fetching Weather Data

Let’s imagine a SOAP service that provides weather data for different cities. You can use Postman to send a request and retrieve the weather information for a specific city.

Step 1: Define Your Request:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:weather="http://www.example.com/weather/webservices">
<soapenv:Header/>
<soapenv:Body>
<weather:GetWeatherByCity>
<weather:city>London</weather:city>
</weather:GetWeatherByCity>
</soapenv:Body>
</soapenv:Envelope>

Step 2: Set Up the Environment:

  • soapEndpoint: https://www.example.com/weather/service
  • soapNamespace: http://www.example.com/weather/webservices

Step 3: Send the Request: Replace the hardcoded city name with a variable like {{city}}. Send the request and inspect the response, which will contain details about the weather in the specified city.

7. SOAP Testing with Postman

Postman provides powerful testing capabilities for validating SOAP responses. Here’s how you can incorporate tests into your SOAP workflows:

  • Tests Tab: Use the “Tests” tab in Postman to write assertions and validate the response data.
  • Built-in Assertions: Use Postman’s built-in assertions like pm.test("Status code is 200", function () {pm.response.to.have.status(200);}) to check for status code, response headers, or body content.
  • Custom Tests: Write custom JavaScript code to perform more complex validation against your SOAP response.

8. Conclusion

Postman streamlines the process of interacting with SOAP services, providing a user-friendly interface for constructing and sending requests. Its extensive features, including environment variables and testing capabilities, empower API developers and testers to effectively design, execute, and verify SOAP interactions.

API Testing Blog