【问题标题】:How to send request to a method of Web Service from Postman?如何从 Postman 向 Web 服务的方法发送请求?
【发布时间】:2022-12-08 21:23:05
【问题描述】:

我有一个 ASMX 服务,它有以下方法。我想调试这个方法,所以我在上面设置了一个断点。但是我无法成功向它发送请求,它给出了 404 错误。

[WebMethod]
public void RequestNotification()
{

到目前为止,我已经尝试过这些选项。

页面截图供参考。

这就是我从 C# 代码调用的方式,这也没有在服务的方法 RequestNotification 上遇到断点。并且它在 C# 代码中也没有给出任何异常。

MyService myService= new MyService ();
myService.RequestNotification();

更新:我已经按照下面的答案进行了尝试,我仍然收到 404。

请在下面找到请求屏幕截图。

【问题讨论】:

    标签: c# asp.net http postman asmx


    【解决方案1】:

    使用来自 Postman 的 POST 调用和 XML Body

    演示代码。 我将为Add 操作展示这个Calculator SOAP service

    发布网址

    http://www.dneonline.com/calculator.asmx
    

    在带有XML 光线选择的体内

    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
      <soap:Body>
        <Add xmlns="http://tempuri.org/">
          <intA>100</intA>
          <intB>200</intB>
        </Add>
      </soap:Body>
    </soap:Envelope>
    

    我从服务部门得到了回应

    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <soap:Body>
            <AddResponse xmlns="http://tempuri.org/">
                <AddResult>300</AddResult>
            </AddResponse>
        </soap:Body>
    </soap:Envelope>
    

    如果你点击 Postman 的 code 按钮,你也可以获得 curl 命令。

    curl --location --request POST 'http://www.dneonline.com/calculator.asmx' 
    --header 'Content-Type: text/xml; charset=utf-8' 
    --header 'SOAPAction: http://tempuri.org/Add' 
    --data-raw '<?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
      <soap:Body>
        <Add xmlns="http://tempuri.org/">
          <intA>100</intA>
          <intB>200</intB>
        </Add>
      </soap:Body>
    </soap:Envelope>
    '
    

    【讨论】:

    • 谢谢 Bench,我已经按照你说的试过了,还是报同样的错误。我已经用邮递员的请求更新了我的问题,我遗漏了什么或做错了什么?
    猜你喜欢
    • 2018-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多