2016-09-14 162 views
4

我試圖通過POSTMAN chrome擴展發送SOAP請求。我的要求身體在POSTMAN中看起來像這樣。如何通過POSTMAN發送SOAP請求

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

編輯:

點擊在POSTMANGenerate 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類看起來像這樣

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

任何想法,爲什麼?

+1

您顯示了您的請求正文,但請求的其餘部分如何?在Postman中,如果你點擊「生成代碼」並粘貼到這裏,它可能會更有幫助。 – SiKing

+0

@SiKing我按照建議添加了「生成代碼」按鈕生成的代碼片段 –

回答

4

事實證明,它最終非常直截了當。我所做的只是瀏覽到Web服務,然後列出可用的端點。然後點擊GetCustomers鏈接。其中顯示了所需的XML示例。然後我用它作爲請求主體的基礎POSTMAN(您可能會注意到namespaces中的一些與我原來的嘗試不同)。

點擊Generate Code按鈕POSTMAN產生如下:

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參數正確填充!