.NET 客户端使用 AXIS 1.4 SSL Web 服务时出现所有异常“内部服务器错误”

发布于 2024-12-08 11:09:10 字数 2337 浏览 1 评论 0原文

我需要从 .NET 客户端通过 SSL 使用 AXIS 1.4 Web 服务。目前我们实现了 System.Net.WebClient,我们手动创建 XML 请求并将其上传到 Web 服务。这对于获取有效结果非常有效,但是如果发生异常(java.rmi.RemoteException),我们只会返回“Interal Server Error”的 WebException。检查响应不会产生更多详细信息。

如果我们在 Visual Studio 2010 中将服务添加为 .NET 2.0 Web 参考 (SoapHttpClientProtocol),我们将收到所需的 java.rmi.RemoteException 以及纠正问题所需的所有详细信息。但是,有效请求产生的所有响应均为空。

注意:此服务正在被其他(竞争对手的).NET 客户端(我们没有源代码)成功使用。

重申一下:通过 WebClient 的有效请求会收到有效的响应对象,但每个异常都是“内部服务器错误”,通过 Web Reference 的有效请求会收到空响应,但会准确地显示所需的 java.rmi.RemoteException。

目标:有效的响应以及完整的 java.rmi.RemoteExceptions(不是模糊的内部服务器错误),即使我可以抛出 SoapException,这将是一个巨大的改进。

IDE:Visual Studio 2010 SP1

操作系统:Windows 7

.NET:2.0/3.5/4.0(我尝试了所有三个版本,结果相同)

语言:C#

WebClient 代码示例:

var lvResult = "";

        try
        {
            var lvStr = "sample request";
            var client = new WebClient();
            client.Headers.Add("SOAPAction", "SampleRequest");

            lvResult = client.UploadString(cvURL, lvStr);
        }
        catch (Exception ex)
        {

        }

更新:更具体地说,这不是一个如果抛出 Soap 异常,就会出现问题,但是抛出的唯一异常是“WebException”,它似乎不允许我访问故障字符串。以下是我从 AXIS 服务收到的原始肥皂故障:

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soapenv:Body>
<soapenv:Fault>
  <faultcode>soapenv:Server.userException</faultcode>
  <faultstring>java.rmi.RemoteException: Error in posting Request: Code 02 - No UserId for this user name/password.</faultstring>
  <detail>
    <ns1:hostname xmlns:ns1="http://xml.apache.org/axis/">xxxx</ns1:hostname>
  </detail>
</soapenv:Fault>

解决方案:我通过捕获 WebException 并获取异常响应的响应流找到了解决方法 -

    catch(WebException pvEx)
    {
        var lvResponseString = "";

        if (pvEx.Response != null)
        {
            using (var lvStreamReader = new StreamReader(pvEx.Response.GetResponseStream()))
            {
                //This string now contains the xml soap response
                lvResponseString = lvStreamReader.ReadToEnd(); 
            }
        }

    }

I need to consume an AXIS 1.4 Web service over SSL from a .NET client. Currently we implement the System.Net.WebClient, we hand create the XML request and upload it to the web service. This works great for getting back valid results, however if an exception occurs (java.rmi.RemoteException) we only get back a WebException of "Interal Server Error". Inspecting the response yields no more detail.

If we add the service in Visual Studio 2010 as a .NET 2.0 Web Reference (SoapHttpClientProtocol) we receive the desired java.rmi.RemoteException with all the necessary details to rectify the problem. However, all resulting responses from a valid request are null.

Note: This service is being consumed successfully by other (competitors') .NET Clients (to which we do not have the source code).

To reiterate: A valid request via WebClient receives valid response objects but every exception is an "Internal Server Error", a valid request via Web Reference receives null responses but will accurately display the desired java.rmi.RemoteException.

The goal: Valid responses along with complete java.rmi.RemoteExceptions (not vague Internal Server Errors), even if I can get a SoapException to be thrown that'd be a huge improvment.

IDE: Visual Studio 2010 SP1

OS: Windows 7

.NET: 2.0/3.5/4.0 (I have attempted all three versions with the same results)

Language: C#

Example WebClient code:

var lvResult = "";

        try
        {
            var lvStr = "sample request";
            var client = new WebClient();
            client.Headers.Add("SOAPAction", "SampleRequest");

            lvResult = client.UploadString(cvURL, lvStr);
        }
        catch (Exception ex)
        {

        }

UPDATE: To be more specific, this wouldn't be a problem if a Soap exception was being thrown, however the only exception thrown is a "WebException" which doesn't seem to give me access to the faultstring. Below is the raw soap fault I'm receiving from the AXIS service:

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soapenv:Body>
<soapenv:Fault>
  <faultcode>soapenv:Server.userException</faultcode>
  <faultstring>java.rmi.RemoteException: Error in posting Request: Code 02 - No UserId for this user name/password.</faultstring>
  <detail>
    <ns1:hostname xmlns:ns1="http://xml.apache.org/axis/">xxxx</ns1:hostname>
  </detail>
</soapenv:Fault>

SOLUTION: I found a workaround by catching the WebException, and grabbing the response stream for the exception response -

    catch(WebException pvEx)
    {
        var lvResponseString = "";

        if (pvEx.Response != null)
        {
            using (var lvStreamReader = new StreamReader(pvEx.Response.GetResponseStream()))
            {
                //This string now contains the xml soap response
                lvResponseString = lvStreamReader.ReadToEnd(); 
            }
        }

    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北斗星光 2024-12-15 11:09:10

这是一篇关于您遇到的问题的帖子:http://bytes.com/主题/net/answers/427757-soap-faults

我认为您的 AXIS 服务正在返回 SOAPFAULT。您只需要知道如何在 .NET 客户端中处理它。这篇文章对此进行了描述。

此致,
马可·克伦韦克

This is a post on exactly the problem you have: http://bytes.com/topic/net/answers/427757-soap-faults.

I think your AXIS service IS returning a SOAPFAULT. You just need to know how to deal with it in your .NET client. And that is described in this post.

Best regards,
Marco Kroonwijk

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文