【问题标题】:The remote server returned an error: (500) Internal Server Error Web service远程服务器返回错误:(500) Internal Server Error Web 服务
【发布时间】:2018-05-13 17:57:23
【问题描述】:

我正在尝试将 SOAP XML 发送到 oracle 网络服务。服务引用不能正常工作,所以我决定使用 webrequest,但我收到一个错误“远程服务器返回错误:(500) 内部服务器错误。”

   string envelope = System.IO.File.ReadAllText("test.xml");
    byte[] byteArray = Encoding.UTF8.GetBytes(envelope);

    byte[] toEncodeAsBytes = System.Text.ASCIIEncoding.ASCII.GetBytes("xxxxx" + ":" + "xxxxx");
    string credentials = System.Convert.ToBase64String(toEncodeAsBytes);

    HttpWebRequest request =(HttpWebRequest)WebRequest.Create("https://ehpq-test.fa.em2.oraclecloud.com/fscmService/SupplierServiceV2");

    request.Method = "POST";
    request.ContentType = "text/xml;charset=UTF-8";
    request.ContentLength = byteArray.Length;

    request.Headers.Add("Authorization", "Basic " + credentials);

    request.Headers.Add("SOAPAction", "https://ehpq-test.fa.em2.oraclecloud.com/fscmService/SupplierServiceV2");

    Stream dataStream = request.GetRequestStream();
    dataStream.Write(byteArray, 0, byteArray.Length);
    dataStream.Close();

    using (WebResponse response = request.GetResponse())
    {
        using (Stream stream = response.GetResponseStream())
        {
            var doc = XDocument.Load(stream);
        }
    }

【问题讨论】:

  • 只是我的意见,但如果 "服务引用不能很好地工作" 尝试更脆弱的解决方案不是我会选择的方式。使用服务参考,您至少有机会获得比 http 500 更具体的服务故障。
  • @Filburt 因为使用服务引用所有值都被发送,即使我没有设置导致错误的值。客户之前也遇到过这种情况,他们建议改用 webrequest。这是 webrequest 的参考docs.oracle.com/en/cloud/saas/sales/r13-update17d/oesws/…
  • 如果您不在代理类或手工构建的 xml soap 消息中设置值,会有什么不同?如果服务方法需要一个值,则无论您以哪种方式构建请求都会失败。
  • @Filburt 这就是我实际告诉他们的。但他们坚持使用soap xml
  • 最后总是soap xml。使用 Web 服务客户端可以避免您自己构建消息。您唯一的问题是为您要调用的服务方法传递所需的参数。如果缺少所需的输入值,服务将始终拒绝任何构建方式的调用。

标签: c# oracle web-services


【解决方案1】:

从您的客户端代码诊断服务器中发生的问题可能非常困难。如果您有权访问服务器,则可以查看 Web 服务器的错误日志。

例如,在 Ubuntu 上使用 Nginx,您可能希望导航到 /var/log/nginx 目录,然后使用 nanotail -f 查看文件 error.log 或类似名称的完整内容。这将是列出服务器抛出 500 的确切原因的地方。可能不是您的请求格式错误,而是端点在服务器端配置错误。

【讨论】:

  • 我无权访问他们的服务器。顺便说一下是oracle web service
猜你喜欢
  • 2011-09-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-20
  • 1970-01-01
  • 2017-01-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多