如何通过 Postman 发送 SOAP 请求

How to send SOAP request via Postman

我正在尝试通过 Postman chrome 扩展程序发送 SOAP 请求。我的请求正文在 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>

编辑:

单击 Postman 中的 Generate Code 按钮会提供以下代码段:

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>

我在 Visual Studio 中有 Web 服务 运行 并且我在 Web 方法中设置了一个断点,该断点正在被命中,因此请求正在到达端点。

Web 方法签名如下所示:

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

但是GetCustomersRequest参数总是NULL。

GetCustomersRequest class 看起来像这样:

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;
}

知道为什么吗?

最后证明很简单。我所做的只是浏览到 Web 服务,然后列出可用的端点。然后点击GetCustomerslink。其中显示了所需 XML 的示例。然后我将其用作 Postman 中请求主体的基础(您可能会注意到某些 namespaces 与我最初的尝试不同)。

在 Postman 中单击 Generate Code 按钮会产生以下结果:

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>

成功到达终点,但这次 GetCustomersRequest 参数已正确填充!