首页 文章

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

提问于
浏览
0

我在调用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>

我不知道我哪里出错了 .

1 回答

  • 1

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

    • POST
    https://swsim.stamps.com/swsim/swsimv42.asmx
    
    • HEADER
    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命名空间 . 有些人工作很好,有些人很沮丧 .

相关问题