如何解释错误“客户端发现响应内容类型为 'text/html'.. [英] How can the error 'Client found response content type of 'text/html'.. be interpreted

查看:41
本文介绍了如何解释错误“客户端发现响应内容类型为 'text/html'..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 C# 并通过自动生成的 C# 代理对象连接到 WebService.我调用的方法可能会长时间运行,有时会超时.我收到不同的错误,有时我收到 System.Net.WebExceptionSystem.Web.Services.Protocols.SoapException.这些异常具有我可以查询的属性,以查找特定类型的错误,从中我可以向用户显示一个人性化的版本.

I'm using C# and connecting to a WebService via an auto-generated C# proxy object. The method I'm calling can be long running, and sometimes times out. I get different errors back, sometimes I get a System.Net.WebException or a System.Web.Services.Protocols.SoapException. These exceptions have properties I can interrogate to find the specific type of error from which I can display a human-friendly version of to the user.

但有时我只会收到一个 InvalidOperationException,它有以下消息.有没有什么方法可以解释这是什么,而不用挖掘字符串中我认识的东西,这感觉很脏,并且与国际化无关,错误消息可能会以不同的语言返回.

But sometimes I just get an InvalidOperationException, and it has the following Message. Is there any way I can interpret what this is without digging through the string for things I recognize, that feels very dirty, and isn't internationalization agnostic, the error message might come back in a different language.

Client found response content type of 'text/html; charset=utf-8', but expected 'text/xml'.
The request failed with the error message:
--
<html>
    <head>
    <title>Request timed out.</title>
                        <style>
         body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;} 
         p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
         b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
         H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
         H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
         pre {font-family:"Lucida Console";font-size: .9em}
         .marker {font-weight: bold; color: black;text-decoration: none;}
         .version {color: gray;}
         .error {margin-bottom: 10px;}
         .expandable { text-decoration:underline; font-weight:bold;     color:navy;         cursor:hand; }
        </style>
    </head>

    <body bgcolor="white">

            <span><H1>Server Error in '/PerformanceManager' Application.<hr     width=100% size=1 color=silver></H1>

            <h2> <i>Request timed out.</i> </h2></span>

            <font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">

            <b> Description: </b>An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

            <br><br>

            <b> Exception Details: </b>System.Web.HttpException: Request timed out.<br><br>

            <b>Source Error:</b> <br><br>

            <table width=100% bgcolor="#ffffcc">
               <tr>
                  <td>
                      <code>

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.</code>

                  </td>
               </tr>
            </table>

            <br>

            <b>Stack Trace:</b> <br><br>

            <table width=100% bgcolor="#ffffcc">
                   <tr>
                  <td>
                      <code><pre>

[HttpException (0x80004005): Request timed out.]
</pre></code>

                  </td>
               </tr>
            </table>

            <br>

            <hr width=100% size=1 color=silver>

            <b>Version Information:</b> Microsoft .NET Framework Version:2.0.50727.312; ASP.NET Version:2.0.50727.833

            </font>

    </body>
</html>
<!-- 
[HttpException]: Request timed out.
-->
--.

我在网络服务器上尝试捕获该方法.我已经调试了它,并且 web-server 方法毫无例外地返回(大约一分钟后).我还在 Web 服务中添加了一个未处理的异常处理程序,并且没有命中一个断点.一旦 Web 服务返回,我就会在客户端中收到此错误,而不是我预期的结果.

I have a try-catch around the method on the web-server. I have debugged it, and the web-server method returns (after a minute or so) without any exception. I also added an unhandled exception handler in the web service and a breakpoint there wasn't hit. As soon as the web-service returns, I get this error in the client instead of the result I expected.

推荐答案

发生这种情况是因为您的 Web 服务中存在未处理的异常,并且 .NET 运行时吐出其 HTML 黄屏死机服务器错误/异常转储页面,而不是 XML.

This is happening because there is an unhandled exception in your Web service, and the .NET runtime is spitting out its HTML yellow screen of death server error/exception dump page, instead of XML.

由于您的 Web 服务的使用者期望得到 text/xml 标头,而得到的是 text/html,因此它会引发该错误.

Since the consumer of your Web service was expecting a text/xml header and instead got text/html, it throws that error.

您应该解决超时的原因(也许是冗长的 SQL 查询?).

You should address the cause of your timeouts (perhaps a lengthy SQL query?).

另外,在 Jeff Atwood 的博客上查看这篇博文,其中解释了实施全局未处理异常处理程序和使用 SOAP 异常.

Also, checkout this blog post on Jeff Atwood's blog that explains implementing a global unhandled exception handler and using SOAP exceptions.

这篇关于如何解释错误“客户端发现响应内容类型为 'text/html'..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆