在 ASP.NET 客户端中显示 Web 服务肥皂异常响应

发布于 2024-08-04 10:32:13 字数 273 浏览 3 评论 0原文

我正在尝试创建一个测试 Web 服务并抛出 SoapException。但是当我通过浏览器打开服务时,它显示内部服务器错误 - 500。

如果我尝试通过发送手动创建的 SoapRequest(在 stringbuilder 中)来手动使用它,我会在 Visual Studio 本身中收到相同的错误“Servererror - 500” “WebResponse response = req.GetResponse()”行

无论如何我都可以看到“响应 XML 中的错误”。

I am trying to make a Test Webservice and throw a SoapException. But when I open the service through browser, it shows Internal server error - 500.

If i try to consume it manually by sending a manually created SoapRequest (in stringbuilder), I get the same error "Servererror - 500" in Visual Studio itself in the line "WebResponse response = req.GetResponse()"

Is there anyway I can actually see the "fault in response XML".

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

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

发布评论

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

评论(3

彡翼 2024-08-11 10:32:13

听起来服务有问题,需要在服务器端而不是客户端进行调试。我得出这个结论是因为您的客户端代码和网络浏览器有问题。

假设您使用 .NET,您是否启用了在服务器上显示 ASP.NET 错误?有关信息,请参阅本文

更新:

所以您在服务器上抛出错误并希望在客户端上获取错误文本?服务器上的错误应该会导致 500 错误消息,并且不太可能向客户端返回任何 XML。也许您可以将一些内容传递给 SoapException 构造函数?

您是否查看过 SoapException 文档?他们有一些使用 SoapException 的 Detail 属性传递信息的示例。

It sounds like there is something wrong with the service and you need to debug it on the server side rather than the client side. I come to this conclusion because you have a problem with your client code and a web browser.

Assuming you are using .NET have you enabled display of ASP.NET errors on the server? See this article for info.

Update:

So you are throwing an error on the server and want to get the error text on the client? An error on the server is supposed to result in a 500 error message and is unlikely to return any XML to the client. Perhaps you can pass something to the SoapException constructor?

Have you looked at the docs for SoapException? They have some examples of passing information using the Detail property of SoapException.

温馨耳语 2024-08-11 10:32:13

您能否在浏览器中访问 asmx(假设您正在使用 asmx)来查看它是否正常工作?

Can you get to the asmx (assuming you are using asmx) in the browser to see if it is working at all?

成熟稳重的好男人 2024-08-11 10:32:13

浏览了 5-6 小时后终于得到了......这里是:

当您手动获取响应时,请使用以下命令:

try
{
    WebResponse response = req.GetResponse();                
    Stream str = response.GetResponseStream();
    StreamReader rdr = new StreamReader(str);
    Response.Write(rdr.ReadToEnd());          
    Response.End();
}
catch (WebException webEx)
{
    Stream str = webEx.Response.GetResponseStream();
    StreamReader rdr = new StreamReader(str); 
    Response.Write(rdr.ReadToEnd());          
    Response.End();
}

after surfing through for 5-6 hours finally got it......here it is:

When you are getting the response manually, use the following:

try
{
    WebResponse response = req.GetResponse();                
    Stream str = response.GetResponseStream();
    StreamReader rdr = new StreamReader(str);
    Response.Write(rdr.ReadToEnd());          
    Response.End();
}
catch (WebException webEx)
{
    Stream str = webEx.Response.GetResponseStream();
    StreamReader rdr = new StreamReader(str); 
    Response.Write(rdr.ReadToEnd());          
    Response.End();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文