-2

I just saw this code here: enter link description here and its seems preatty good, but I don't know how to use it. I have to call it from the controller? How can I use the information that it is returned? I am very new with Web Services, so I'm not very sure how to use it.

   public async Task<string> CreateSoapEnvelope()
    {
  string soapString = @"<?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>
              <HelloWorld xmlns=""http://tempuri.org/"" />
          </soap:Body>
      </soap:Envelope>";

      HttpResponseMessage response = await PostXmlRequest("your_url_here", soapString);
      string content = await response.Content.ReadAsStringAsync();

  return content;
  } 

  public static async Task<HttpResponseMessage> PostXmlRequest(string baseUrl, string 
  xmlString)
  {
      using (var httpClient = new HttpClient())
     {
      var httpContent = new StringContent(xmlString, Encoding.UTF8, "text/xml");
      httpContent.Headers.Add("SOAPAction", "http://tempuri.org/HelloWorld");

      return await httpClient.PostAsync(baseUrl, httpContent);
     }
}
  • I would really recommend NOT hand crafting XML and especially SOAP messages. There are so many tools out there that will do this properly. Use the WebServices feature built in the Visual Studio. – Neil May 19 '22 at 21:07

0 Answers0