(500) Internal Server Error

I am getting the Error below when calling the Authenticate method of Stamps.com webservice.

The remote server returned an error: (500) Internal Server Error.

Here is the SOAP 1.1 definition of the request.

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"

<?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>
    <AuthenticateUser xmlns="http://stamps.com/xml/namespace/2015/05/swsim/swsimv45">
      <Credentials>
        <IntegrationID>guid</IntegrationID>
        <Username>string</Username>
        <Password>string</Password>
      </Credentials>
    </AuthenticateUser>
  </soap:Body>
</soap:Envelope>

Here is my code calling the service.

private void button2_Click(object sender, EventArgs e)
{
    CallStampsService();
}

private void CallStampsService()
{
    HttpWebRequest request = CreateHTTPWebRequest();
    XmlDocument soapEnvelopeXml = new XmlDocument();
    soapEnvelopeXml.LoadXml(@"<?xml version=""1.0"" encoding=""utf-8""?>
    <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"">
    <soap:Body>
        <AuthenticateUser>
           <Credentials>
            <IntegrationID>my_integration_id</IntegrationID>
            <Username>my_username</Username>
            <Password>my_password</Password>
           </Credentials>
        </AuthenticateUser>
    </soap:Body>
    </soap:Envelope>");

    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;
}

}

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.

<faultstring>Server did not recognize the value of HTTP Header SOAPAction: http://stamps.com/xml/namespace/2015/05/swsim/swsimv45.</faultstring>

So I inspected my Header object and got this.

{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
}

The application fails at this line.

WebResponse response = request.GetResponse()

So I inspected the innerXML and got this.

<?xml version="1.0" encoding="utf-8"?>
<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">
    <soap:Body>
        <AuthenticateUser>
            <Credentials>
                <IntegrationID>my_integrationID</IntegrationID>
                <Username>my_username</Username>
                <Password>my_password</Password>
            </Credentials>
        </AuthenticateUser>
    </soap:Body>
</soap:Envelope>

I do not know where I am going wrong.


I feel your pain. I've used the method below with success:

-- POST

https://swsim.stamps.com/swsim/swsimv42.asmx

-- HEADER

SOAPAction: http://stamps.com/xml/namespace/2015/01/swsim/swsimv42/AuthenticateUser
Content-type: text/xml

-- BODY

<?xml version="1.0" encoding="utf-8"?>
<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">

<soap:Body>
    <AuthenticateUser xmlns="http://stamps.com/xml/namespace/2015/01/swsim/swsimv42">
      <Credentials>
        <IntegrationID>XXXXXXX</IntegrationID>
        <Username>XXXXXXX</Username>
        <Password>XXXXXXX</Password>
      </Credentials>
    </AuthenticateUser>
</soap:Body>
</soap:Envelope>

Please note there are numerous versions of the stamps.com namespaces. Some work great, others are frustrating.

链接地址: http://www.djcxy.com/p/45930.html

上一篇: 如何使用C#创建简单的Web代理服务器?

下一篇: (500内部服务器错误