首页 > 解决方案 > 如何在soap web services c#中请求并获取响应

问题描述

我有 .asmx url,我需要按订单号获取订单详细信息。

我的问题是,当我执行代码时,它会带回“ http://domain.co.za/services/portal.asmx?op=GetOrderDefinition ”的 html 设计而不填充响应。这是我的代码

 var client = new RestClient("http://domain.co.za/services/portal.asmx?op=GetOrderDefinition");
        var requests = new RestRequest(Method.GET);

        client.Proxy = WebRequest.DefaultWebProxy;
        client.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;

        requests.AddHeader("Host", "test.lensportal.co.za");
        requests.AddHeader("Content-Type", "text/xml; charset=utf-8");
        requests.AddHeader("SOAPAction", "http://www.domain.co.za/GetOrderDefinition");

        requests.AddParameter("{\r\n  \"orderRef\": \"" + LabOrderReference + "\"\r\n}", RestSharp.ParameterType.RequestBody);
        IRestResponse responses = client.Execute(requests);

链接“ http://domain.co.za/services/portal.asmx?op=GetOrderDefinition ”包含下面的示例,我需要在请求时传递“orderRef”并从订单详细信息中取回列表。请注意,该链接还具有 SOAP 1.1 响应设计,现在我只包含请求部分。

POST /services/portal.asmx HTTP/1.1
Host: test.lensportal.co.za
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://www.domain.co.za/GetOrderDefinition"


<?xml version="1.0" encoding="utf-8"?>
<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>
 <GetOrderDefinition xmlns="http://www.domain.co.za">
<orderRef>string</orderRef>
</GetOrderDefinition>
</soap:Body>
</soap:Envelope>

标签: c#webrequest

解决方案


推荐阅读