【问题标题】:Stamps.com webservice Error - (500) Internal Server ErrorStamps.com 网络服务错误 - (500) 内部服务器错误
【发布时间】:2016-02-12 23:08:04
【问题描述】:

调用 Stamps.com 网络服务的 Authenticate 方法时出现以下错误。

远程服务器返回错误:(500) Internal Server Error.

这是请求的 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 响应 = 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>

我不知道我哪里出错了。

【问题讨论】:

标签: c# xml web-services stamps.com


【解决方案1】:

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

--发布

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

【讨论】:

    猜你喜欢
    • 2015-11-10
    • 1970-01-01
    • 2019-01-17
    • 2011-10-17
    • 2010-11-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多