title: C# Soap 1.2 WebService
body: <p>I am having an issue when calling an external third-part soap web service: the error am getting is 'The remote server returned an error: (500) Internal Server Error.'(from client), but the problem is when I do call using SoapUI 5.4.0 (on the same PC under the same user) it runs fine. The code works on any other web services. </p>
  
  <p>Can someone give me any idea?</p>
  
  <pre><code>using System;
  using System.IO;
  using System.Net;
  using System.Xml;
  
  namespace ConsoleApp1
  {
  class Program
  
  /// Soap WebService call
  
      public static void Execute()
      {
          HttpWebRequest request = CreateWebRequest();
          request.Credentials = CredentialCache.DefaultCredentials;
          XmlDocument soapEnvelopeXml = new XmlDocument();
          NewMethod(soapEnvelopeXml);
  
          using (Stream stream = request.GetRequestStream())
          {
              soapEnvelopeXml.Save(stream);
          }
  
          using (WebResponse response = request.GetResponse())
          {
              Console.WriteLine(((HttpWebResponse)response).StatusDescription);
              using (StreamReader rd = new StreamReader(response.GetResponseStream()))
              {
                  string soapResult = rd.ReadToEnd();
                  Console.WriteLine(soapResult);
                  Console.WriteLine("Done!");
                  Console.ReadKey();
  
              }
          }
      }
  
      private static void NewMethod(XmlDocument soapEnvelopeXml)
      {
              soapEnvelopeXml.LoadXml(xml: @"&lt;soap:Envelope xmlns:soap=""http://www.w3.org/2003/05/soap-envelope"" xmlns:out=""http://www.test.com/test/Services/Outage""&gt;&lt;soap:Header/&gt;&lt;soap:Body&gt;&lt;out:GetLocations/&gt;&lt;/soap:Body&gt;&lt;/soap:Envelope&gt;");
  
      }
  
  
  
      /// Create a soap webrequest to [Url]
      public static HttpWebRequest CreateWebRequest()
      {
           HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("http://test:557/OutageService.svc");
  
          webRequest.ContentType = @"application/soap+xml;charset=UTF-8";
          webRequest.Accept = "text/xml";
          webRequest.Method = "POST";
          return webRequest;
      }
  
      static void Main(string[] args)
      {
          Execute();
  
      }
  
   }
  }
  </code></pre>
  
  <p>And SoapUI 5.4.0 (I've changed the domain name to 'test')</p>
  
  <p>XML</p>
  
  <pre><code>&lt;soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:out="http://www.test.com/test/Services/Outage"&gt;
  &lt;soap:Header/&gt;
   &lt;soap:Body&gt;
     &lt;out:GetLocations/&gt;
   &lt;/soap:Body&gt;
  &lt;/soap:Envelope&gt;
  </code></pre>
  
  <p>RAW</p>
  
  <pre><code>POST http://test:557/OutageService.svc HTTP/1.1
   Accept-Encoding: gzip,deflate
   Content-Type:   application/soap+xml;charset=UTF-8;action="http://www.test.com/test/Services/Outage/IOutageService/GetLocations"
   Content-Length: 390
   Host: test:557
   Connection: Keep-Alive
   User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
  </code></pre>
  
  <p>Respond</p>
  
  <pre><code>HTTP/1.1 200 OK 
  Cache-Control: private
  Content-Length: 155883
  Content-Type: application/soap+xml; charset=utf-8
  Server: Microsoft-IIS/8.5
  X-AspNet-Version: 4.0.30319
  X-Powered-By: ASP.NET
  Date: Mon, 12 Mar 2018 16:09:46 GMT
  
  &lt;s:Envelope xmlns:s="http://www.w3.org/2003/05/so.........
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/MJ0GI.png" rel="nofollow noreferrer">SoapUI</a></p>