title: .NET service responds 500 internal error and "missing parameter" to HttpWebRequest POSTS but test form works fine
body: <p>I am using a simple .NET service (asmx) that works fine when invoking via the test form (POST).  When invoking via a HttpWebRequest object, I get a WebException "System.Net.WebException: The remote server returned an error: (500) Internal Server Error."  Digging deeper, reading the WebException.Response.GetResponseStream() I get the message: "Missing parameter: serviceType." but I've clearly included this parameter.</p>
  
  <p>I'm at a loss here, and its worse that I don't have access to debug the service itself.</p>
  
  <p>Here is the code being used to make the request:</p>
  
  <pre><code>string postData = String.Format("serviceType={0}&amp;SaleID={1}&amp;Zip={2}", request.service, request.saleId, request.postalCode);
  byte[] data = (new ASCIIEncoding()).GetBytes(postData);
  
  HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
  httpWebRequest.Timeout = 60000;
  httpWebRequest.Method = "POST";
  httpWebRequest.ContentType = "application/x-www-form-urlencoded";
  httpWebRequest.ContentLength =  data.Length;
  
  using (Stream newStream = httpWebRequest.GetRequestStream())
  {
      newStream.Write(data, 0, data.Length);
  }
  
  try
  {
      using (response = (HttpWebResponse)httpWebRequest.GetResponse())
      {
          if (response.StatusCode != HttpStatusCode.OK)
              throw new Exception("There was an error with the shipping freight service.");
  
          string responseData;
          using (StreamReader responseStream = new      StreamReader(httpWebRequest.GetResponse().GetResponseStream(),    System.Text.Encoding.GetEncoding("iso-8859-1")))
          {
              responseData = responseStream.ReadToEnd();
              responseStream.Close();
          }
  
          if (string.IsNullOrEmpty(responseData))
              throw new Exception("There was an error with the shipping freight service.  Request went through but response is empty.");
  
          XmlDocument providerResponse = new XmlDocument();
          providerResponse.LoadXml(responseData);
  
          return providerResponse;
      }
  }
  catch (WebException webExp)
  {
      string exMessage = webExp.Message;
  
      if (webExp.Response != null)
      {
          using (StreamReader responseReader = new StreamReader(webExp.Response.GetResponseStream()))
          {
              exMessage = responseReader.ReadToEnd();
          }
      }
  
      throw new Exception(exMessage);
  }
  </code></pre>
  
  <p>Anyone have an idea what could be happening?</p>
  
  <p>Thanks.</p>
  
  <p>UPDATE</p>
  
  <p>Stepping through the debugger, I see the parameters are correct.  I also see the parameters are correct in fiddler.</p>
  
  <p>Examining fiddler, I get 2 requests each time this code executes.  The first request is a post that sends the parameters.  It gets a 301 response code with a "Document Moved Object Moved This document may be found here" message.  The second request is a GET to the same URL with no body.  It gets a 500 server error with "Missing parameter: serviceType." message.</p>