Stamps.com Web 服务错误 - (500) 内部服务器错误

本文关键字:错误 内部 服务器 com Web 服务 Stamps | 更新日期: 2023-09-27 18:34:34

我在调用 Web 服务的身份验证方法时收到以下错误 Stamps.com。

远程服务器返回错误: (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
}

应用程序在此行失败。

网络响应响应 = 请求。获取响应((

所以我检查了内部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'"
    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>

我不知道我哪里出错了。

Stamps.com Web 服务错误 - (500) 内部服务器错误

我能感受到你的痛苦。我已经成功地使用了以下方法:

--发布

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 命名空间有许多版本。有些工作得很好,有些则令人沮丧。

是的,邮票文档非常令人困惑。特别是在他们的一堆WSDL版本中。但他们的支持者的回答令人惊讶地提供了丰富的信息。http://stamps.com/xml/namespace/2015/05/swsim/swsimv45 xmls引用位于错误的位置。但他们没有告诉你。以及为什么。

xmls引用命名空间 class,其中存储了引用它的实体的定义。

例如,<AuthenticateUser xmlns="http://stamps.com/xml/namespace/2015/01/swsim/swsimv42">告诉AuthenticateUser的定义位于http://stamps.com/xml/namespace/2015/01/swsim/swsimv42命名空间中。位于自定义命名空间中的非全局 SOAP 元素(自定义(。这里一切都很好。

或者<soap:Envelope ... mlns:tns=""http://stamps.com/xml/namespace/2015/05/swsim/swsimv45"">告诉soap元素的描述应该从http://stamps.com/xml/namespace/2015/05/swsim/swsimv45命名空间中使用。但soap:Envelope元素对于 SOAP 来说是全局的。本地命名空间没有它的定义。这就是出现错误的原因。

要解决此问题,您需要在适当的位置引用该命名空间。将其从<soap:Envelope ...>移动到<身份验证用户...>.你的 SOAP 信封就可以了。

P. S. 知道,这个问题很老了。但它没有得到回答,可以帮助那些用谷歌搜索它的人。