How to Call a Soap Web Service from Asp.Net Core 3.1

Question: How do you call a web service that uses XML Soap Envelope as Payload Body?

Login to See the Rest of the Answer

When working with Old Protocol like the Soap Web Service Protocol in Asp.Net Core 3.1, you can craft the Web Request just the same as would when calling an API, however, different Web Services require different Header Parameter to be passed, it would only help if you find out the requirement for making a Soap Web Request in Asp.Net Core 3.1. For example, code, see the code below:

 var client = new RestClient("https://FirstLevelDomain/urlEndPoint.asmx?op=NameOfFunction");
            client.Timeout = -1;
            var request = new RestRequest(Method.POST);
            request.AddHeader("Host", "DomainNameWithoutHttps");
            request.AddHeader("Content-Type", "text/xml");
            request.AddHeader("charset", "utf-8");
            request.AddHeader("SOAPAction", "\"http://DomainWithoutHttps/NameOfFunction\"");
            request.AddParameter("text/xml", "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<soap:Envelope xmlns:xsi=\"\" xmlns:xsd=\"\" xmlns:soap=\"\">\r\n  <soap:Body>\r\n    <NameOfFunction xmlns=\"\">\r\n      <ParameterYouWantToPass>"+ paramValue + "</clientId>\r\n  </soap:Body>\r\n</soap:Envelope>", ParameterType.RequestBody);
            IRestResponse response = await client.ExecuteAsync(request);



If you log in, you will be notified when someone leaves a comment.

Other users would like to know if this solution helped you.

© 2023 - ErnesTech LLC- Privacy