(500内部服务器错误

调用Stamps.com webservice的Authenticate方法时,我收到以下错误消息。

远程服务器返回错误:(500)内部服务器错误。

这是请求的SOAP 1.1定义。

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>

这是我的代码调用服务。

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

}

我联系了Stamps.com,他们的支持人员表示他们无法提供有关代码的很多帮助,但表示他们的结尾出现以下错误。

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

所以我检查了我的Header对象并得到了这个。

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

应用程序在此行失败。

WebResponse response = request.GetResponse()

所以我检查了innerXML并得到了这个。

<?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>

我不知道我哪里错了。


我感到你的痛苦。 我已经用下面的方法成功了:

- POST

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

- 标题

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

- 身体

<?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>

请注意,stamps.com命名空间有很多版本。 有些工作很棒,其他人则很沮丧。

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

上一篇: (500) Internal Server Error

下一篇: Getting Internal Server Error