Skip to content

How To Use Postman To Test Soap Web Service

API Testing Blog

Testing SOAP Web Services with Postman

While Postman is primarily known for its REST API testing capabilities, it also provides powerful tools for testing SOAP web services. This guide covers the essential steps involved in using Postman to test SOAP web services, including practical examples and step-by-step instructions.

Understanding SOAP and Postman

SOAP (Simple Object Access Protocol) is a messaging protocol built on XML that allows applications to exchange data over a network. Postman, while initially designed for REST APIs, supports versatile testing through its powerful request builder and the ability to handle custom headers and XML payloads.

Setting Up Your Postman Environment

To test SOAP web services in Postman, you need to:

  1. Install Postman: Download and install Postman from https://www.postman.com/.

  2. Create a New Collection: In Postman, create a new collection dedicated to your SOAP API testing.

Building a Simple SOAP Request

Let’s use a simple example of a weather forecast service that returns the current temperature for a given city.

Step 1: Define the Request Type

  • Select the POST method as SOAP requests are typically sent using the POST method.

Step 2: Specify the Request URL

  • Replace "https://www.example.com/weatherforecast" with the actual endpoint URL of your SOAP web service.
  • This URL will point to the specific WSDL (Web Services Description Language) document that describes the web service’s functionality.
https://www.example.com/weatherforecast

Step 3: Configure Headers

Postman provides an intuitive interface for adding headers to your SOAP requests.

  • Content-Type: Set the content type to application/soap+xml.
  • SOAPAction: This header specifies the SOAP operation you want to perform. For our example, it might be GetWeatherForecast.
Content-Type: application/soap+xml
SOAPAction: "http://www.example.com/weatherforecast#GetWeatherForecast"

Step 4: Craft the SOAP Body

In the body section of your request, you’ll construct the SOAP envelope containing the actual request.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:wfs="http://www.example.com/weatherforecast">
<soapenv:Header/>
<soapenv:Body>
<wfs:GetWeatherForecast>
<wfs:cityName>London</wfs:cityName>
</wfs:GetWeatherForecast>
</soapenv:Body>
</soapenv:Envelope>

Explanation:

  • The soapenv:Envelope tag encloses the entire SOAP message.
  • The soapenv:Body tag contains the actual request to the web service.
  • Replace "London" with the city you’d like to query.
  • Ensure namespaces are correctly defined.

Sending the SOAP Request and Analyzing the Response

  1. Send the Request: Click on the “Send” button in Postman to send your SOAP request.
  2. Inspect the Response: The response from the SOAP service will be displayed in the response tab.

Step 5: Parse the Response (XML)

The response will be in XML format. Postman provides tools to view it as XML, JSON, or plain text. You can:

  1. Use the built-in XML viewer: Postman provides a visual XML viewer for easy navigation and inspection.

  2. Extract Values: Use Postman’s scripting capabilities (using JavaScript) to extract specific data elements from the XML response.

Using Postman’s “SOAP” Tab for More Sophisticated Testing

For more complex SOAP web services, Postman offers a dedicated “SOAP” tab that provides additional functionality:

Step 6: WSDL Integration

  • Import WSDL: You can import the WSDL for your web service, allowing Postman to automatically generate requests and handle namespaces.

Step 7: Testing Multiple Operations

  • Explore operations: The WSDL importation allows you to view available operations defined in your service. Each operation will have predefined input parameters, which Postman automatically maps for you.

Step 8: Generating Code (Optional)

  • Code generation: Postman can even generate code snippets for various programming languages, simplifying integration of your SOAP service into your application.

Examples

Example 1: Testing a Stock Quote Web Service

Suppose you have a stock quote web service with the following endpoint: https://www.example.com/stockquotes.

Request Body (XML):

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:qws="http://www.example.com/stockquotes">
<soapenv:Header/>
<soapenv:Body>
<qws:GetStockQuote>
<qws:symbol>AAPL</qws:symbol>
</qws:GetStockQuote>
</soapenv:Body>
</soapenv:Envelope>

Example 2: Testing a Banking Service

Imagine a banking service with an endpoint https://www.example.com/banking that allows you to check account balances.

Request Body (XML):

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:bws="http://www.example.com/banking">
<soapenv:Header/>
<soapenv:Body>
<bws:GetAccountBalance>
<bws:accountId>1234567890</bws:accountId>
</bws:GetAccountBalance>
</soapenv:Body>
</soapenv:Envelope>

Best Practices for Testing using Postman

  • Use Environments: Store endpoint URLs, credentials, and other configurations as environment variables. This allows for easy switching between production and testing environments.
  • Automate Tests: Leverage Postman’s scripting features to create automated tests for frequently used SOAP requests. Use the pm.test() function to assert expected results in your response.
  • Utilize Collections: Organize and manage your SOAP tests within collections. This makes it easier to maintain, run, and share tests with your team.
  • Document Your Tests: Add detailed descriptions to each request and test. This helps in understanding the purpose and functionality of each test later on.

By following these guidelines, you can leverage Postman effectively to test your SOAP web services and ensure their reliability and functionality.

API Testing Blog