title: Stamps.com webservice Error - (500) Internal Server Error
body: <p>I am getting the Error below when calling the Authenticate method of Stamps.com webservice.</p>
  
  <blockquote>
    <p>The remote server returned an error: (500) Internal Server Error.</p>
  </blockquote>
  
  <p>Here is the SOAP 1.1 definition of the request.</p>
  
  <pre><code>POST /swsim/SwsimV45.asmx HTTP/1.1
  Host: swsim.testing.stamps.com
  Content-Type: text/xml; charset=utf-8
  Content-Length: length
  SOAPAction: "http://stamps.com/xml/namespace/2015/05/swsim/swsimv45/AuthenticateUser"
  
  &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;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/"&gt;
    &lt;soap:Body&gt;
      &lt;AuthenticateUser xmlns="http://stamps.com/xml/namespace/2015/05/swsim/swsimv45"&gt;
        &lt;Credentials&gt;
          &lt;IntegrationID&gt;guid&lt;/IntegrationID&gt;
          &lt;Username&gt;string&lt;/Username&gt;
          &lt;Password&gt;string&lt;/Password&gt;
        &lt;/Credentials&gt;
      &lt;/AuthenticateUser&gt;
    &lt;/soap:Body&gt;
  &lt;/soap:Envelope&gt;
  </code></pre>
  
  <p>Here is my code calling the service.</p>
  
  <pre><code>private void button2_Click(object sender, EventArgs e)
  {
      CallStampsService();
  }
  
  private void CallStampsService()
  {
      HttpWebRequest request = CreateHTTPWebRequest();
      XmlDocument soapEnvelopeXml = new XmlDocument();
      soapEnvelopeXml.LoadXml(@"&lt;?xml version=""1.0"" encoding=""utf-8""?&gt;
      &lt;soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"" 
         xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" 
         xmlns:xsd=""http://www.w3.org/2001/XMLSchema""
         xmlns:tns=""http://stamps.com/xml/namespace/2015/05/swsim/swsimv45""&gt;
      &lt;soap:Body&gt;
          &lt;AuthenticateUser&gt;
             &lt;Credentials&gt;
              &lt;IntegrationID&gt;my_integration_id&lt;/IntegrationID&gt;
              &lt;Username&gt;my_username&lt;/Username&gt;
              &lt;Password&gt;my_password&lt;/Password&gt;
             &lt;/Credentials&gt;
          &lt;/AuthenticateUser&gt;
      &lt;/soap:Body&gt;
      &lt;/soap:Envelope&gt;");
  
      using (Stream stream = request.GetRequestStream())
      {
          soapEnvelopeXml.Save(stream);
      }
  
      using (WebResponse response = request.GetResponse())
      {
          using (StreamReader rd = new StreamReader(response.GetResponseStream()))
          {
              string soapResult = rd.ReadToEnd();
              MessageBox.Show(soapResult);
          }
      }
  
  }
  
  public static HttpWebRequest CreateHTTPWebRequest()
  {
      HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(@"https://swsim.testing.stamps.com/swsim/SwsimV45.asmx");
      webRequest.Headers.Add(@"SOAPAction: " + @"http://stamps.com/xml/namespace/2015/05/swsim/swsimv45/AuthenticateUser");
      webRequest.ContentType = "text/xml;charset=utf-8";
      webRequest.Accept = "text/xml";
      webRequest.Method = "POST";
      return webRequest;
  }
  
  }
  </code></pre>
  
  <p>I contacted Stamps.com and their support said they can't offer much assistance regarding the code, but indicated that the following error appears on their end.</p>
  
  <pre><code>&lt;faultstring&gt;Server did not recognize the value of HTTP Header SOAPAction: http://stamps.com/xml/namespace/2015/05/swsim/swsimv45.&lt;/faultstring&gt;
  </code></pre>
  
  <p>So I inspected my Header object and got this.</p>
  
  <pre><code>{SOAPAction: http://stamps.com/xml/namespace/2015/05/swsim/swsimv45/AuthenticateUser
  Content-Type: text/xml;charset=utf-8
  Accept: text/xml
  Host: swsim.testing.stamps.com
  Content-Length: 580
  Expect: 100-continue
  Connection: Keep-Alive
  }
  </code></pre>
  
  <p>The application fails at this line.</p>
  
  <blockquote>
    <p>WebResponse response = request.GetResponse()</p>
  </blockquote>
  
  <p>So I inspected the innerXML and got this.</p>
  
  <pre><code>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;
  &lt;soap:Envelope
      xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"
      xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
      xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"
      xmlns:tns=\"http://stamps.com/xml/namespace/2015/05/swsim/swsimv45\"&gt;
      &lt;soap:Body&gt;
          &lt;AuthenticateUser&gt;
              &lt;Credentials&gt;
                  &lt;IntegrationID&gt;my_integrationID&lt;/IntegrationID&gt;
                  &lt;Username&gt;my_username&lt;/Username&gt;
                  &lt;Password&gt;my_password&lt;/Password&gt;
              &lt;/Credentials&gt;
          &lt;/AuthenticateUser&gt;
      &lt;/soap:Body&gt;
  &lt;/soap:Envelope&gt;
  </code></pre>
  
  <p>I do not know where I am going wrong. </p>