title: .NET Web Service receive HTTP POST request (500) Internal Server Error
body: <p>I am currently writing a C# web service which has several methods, one of which has to receive HTTP POST requests. The first thing i have done is alter the web.config file in the web service project as below.</p>
  
  <pre><code>&lt;webServices&gt;
    &lt;protocols&gt;
      &lt;add name="HttpSoap"/&gt;
      &lt;add name="HttpPost"/&gt;
      &lt;add name="HttpPostLocalhost"/&gt;
      &lt;add name="Documentation"/&gt;
    &lt;/protocols&gt;
  &lt;/webServices&gt;
  </code></pre>
  
  <p>I can run the web service locally and when i click on the method in the browser, i can see it handles HTTP POST requests and accepts args=string, as my signature of the web method accepts one string parameter named args. I am then testing this via a test ASP.NET app using the code below to fire the HTTP POST request.</p>
  
  <pre><code>HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(ConfigurationManager.AppSettings["PaymentHubURL"].ToString());
  
  request.KeepAlive = false;
  request.ContentType = "application/x-www-form-urlencoded";
  request.Method = "POST";
  
  StringBuilder sb = new StringBuilder();
  sb.Append("message_type=");
  sb.Append(HttpUtility.UrlEncode("Txn_Response"));
  
  byte[] bytes = UTF8Encoding.UTF8.GetBytes(sb.ToString());
  request.ContentLength = bytes.Length;
  using (Stream postStream = request.GetRequestStream())
  {
      postStream.Write(bytes, 0, bytes.Length);
  }
  
  string test;
  using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
  {
       StreamReader reader = new StreamReader(response.GetResponseStream());
  
       test = reader.ReadToEnd();
  }
  </code></pre>
  
  <p>But when i run this i get "The remote server returned an error: (500) Internal Server Error". If i remove the parameter, by removing the stringbuilder and byte code, as well as having no parameter in the web service, it works. So it is obviously a problem with the parameters. I actually want to send more data, and was using a string[] parameter in the web service, but this also failed. </p>
  
  <p>Can anyone help??</p>