Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send SOAP request via Postman

I'm trying to send a SOAP request via the Postman chrome extension. My request body looks like this in Postman:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://partnerapi.somewhere.com/">
  <soapenv:Body>
    <ns1:GetCustomers>
      <GetCustomersRequest>
        <APIKey>SECRET</APIKey>
        <PartnerKey></PartnerKey>    
        <SearchText></SearchText>
        <ItemsPerPage>50</ItemsPerPage>
        <PageNumber>1</PageNumber>
        <Fields></Fields>
        <OrderBy></OrderBy>
      </GetCustomersRequest> 
    </ns1:GetCustomers>
  </soapenv:Body>
</soapenv:Envelope>

Edit:

Clicking the Generate Code button in Postman provides the following snippet:

POST /PartnerAPI.asmx HTTP/1.1
Host: localhost:3000
Content-Type: text/xml
SOAPAction: http://partnerapi.somewhere.com/GetCustomers
Cache-Control: no-cache
Postman-Token: 1af78251-9d36-0c94-d0e3-21f7e37ffc41
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://partnerapi.somewhere.com/">
  <soapenv:Body>
    <ns1:GetCustomers>
      <GetCustomersRequest>
        <APIKey>SECRET</APIKey>
        <PartnerKey></PartnerKey>    
        <SearchText></SearchText>
        <ItemsPerPage>50</ItemsPerPage>
        <PageNumber>1</PageNumber>
        <Fields></Fields>
        <OrderBy></OrderBy>
      </GetCustomersRequest> 
    </ns1:GetCustomers>
  </soapenv:Body>
</soapenv:Envelope>

I have the web service running in Visual Studio and I have a breakpoint set in the web method which is being hit so the request is reaching the endpoint.

The web method signature looks like this:

[WebMethod]
public CustomersObject GetCustomers(RequestObjects.GetCustomersRequest GetCustomersRequest)

But the GetCustomersRequest parameter is always NULL.

The GetCustomersRequest class looks like this:

public class GetCustomersRequest {
    public string APIKey;
    public string PartnerKey;
    public string SearchText;
    public int ItemsPerPage = 50;
    public int PageNumber = 1;

    public string Fields;
    public string OrderBy;
}

Any idea why?

like image 820
Simon Lomax Avatar asked Sep 14 '16 15:09

Simon Lomax


People also ask

Can Postman handle SOAP request?

Postman is a trusty tool to handle any API that can utilize HTTP—like REST, SOAP, and GraphQL.

How is a SOAP request sent?

To make SOAP requests to the SOAP API endpoint, use the "Content-Type: application/soap+xml" request header, which tells the server that the request body contains a SOAP envelope. The server informs the client that it has returned a SOAP envelope with a "Content-Type: application/soap+xml" response header.

How will you generate SOAP request from WSDL in Postman?

Open Postman and click on Import > Link and paste the link to the WSDL file. Click on Continue. Finally, click on Import. The collection will be added to your existing Postman collections.


1 Answers

It turned out to be quite straight forward in the end. All I did was browse to the web service, which then lists the endpoints available. Then clicked on the GetCustomers link. Which shows an example of the XML required. I then used that as the basis for the request body in Postman (You may notice that some of the namespaces are different from my original attempt).

Clicking the Generate Code button in Postman produces the following:

POST /PartnerAPI.asmx HTTP/1.1
Host: localhost:53355
Content-Type: text/xml; charset=utf-8
SOAPAction: http://partnerapi.somewhere.com/GetCustomers
Cache-Control: no-cache
Postman-Token: 914d2152-9063-ff57-91a0-e567714c2d44
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <GetCustomers xmlns="http://partnerapi.somewhere.com/">
      <GetCustomersRequest>
        <APIKey>SECRET</APIKey>
        <SearchText></SearchText>
        <ItemsPerPage>10</ItemsPerPage>
        <PageNumber>1</PageNumber>
        <Fields></Fields>
        <OrderBy></OrderBy>
      </GetCustomersRequest>
    </GetCustomers>
  </soap:Body>
</soap:Envelope>

Which successfully reaches the endpoint but this time the GetCustomersRequest parameter is populated correctly!

like image 51
Simon Lomax Avatar answered Oct 09 '22 12:10

Simon Lomax