How can the error 'Client found response content type of 'text/html'.. be interpreted
Asked Answered
H

10

32

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.

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.
-->
--.

Edit: 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.

Hardily answered 22/9, 2008 at 14:59 Comment(0)
A
47

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.

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

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

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

Ashelyashen answered 22/9, 2008 at 16:44 Comment(3)
URL not found. Any alternative ?Nobell
URL available againDeeply
In my case it won't even hit the code being called in the web service so it can't be an unhandled exception in the web service as it never reaches the web service! It just falsely shows "Source Error:" with "Line 1:" and no code after it!Theorist
S
12

That means that your consumer is expecting XML from the webservice but the webservice, as your error shows, returns HTML because it's failing due to a timeout.

So you need to talk to the remote webservice provider to let them know it's failing and take corrective action. Unless you are the provider of the webservice in which case you should catch the exceptions and return XML telling the consumer which error occurred (the 'remote provider' should probably do that as well).

Stony answered 22/9, 2008 at 15:3 Comment(5)
I wrote the webservice. I'm catching all exceptions on the server, but don't get any. I get this timeout message appearing at the client end before the method on the server end returns.Hardily
@VinkoVrsalovic: Thanks earlier. It's been closed again! I can't help but laugh now though. :)Fecund
Thanks for your answer though. I guess there must be something going on in the middle that I don't understand.Hardily
Are you sure you are catching HttpExceptions?Stony
For me, I had changed the URL for the web-service for IIS and needed to change it back again for the Visual Studio version. I realize this comment is quite late, however.Makeup
I
7

If you are using .NET version 4.0. the validateRequestion is turned on by default for all the pages. in previous versions 1.1 and 2.0 it was only for aspx page. You can turn the default validation off. In that case you have to do the due diligence and make sure that the data is clean. Use HtmlEncode. Do the following to turn the validation off

In the web.config add the following lines for system.web

 <httpRuntime requestValidationMode="2.0" />

and

 <pages validateRequest="false" />

You can read more about this http://www.asp.net/learn/whitepapers/aspnet4/breaking-changes also http://msdn.microsoft.com/en-us/library/ff649310.aspx

Hope this helps.

Ingurgitate answered 1/6, 2011 at 21:0 Comment(0)
C
5

The webserver is returning an http 500 error code. These errors generally happen when an exception in thrown on the webserver and there's no logic to catch it so it spits out an http 500 error. You can usually resolve the problem by placing try-catch blocks in your code.

Candlemaker answered 22/9, 2008 at 16:53 Comment(0)
J
5

I had this happen as a result of a configuration error in web.config. Checking the connection string etc might be the answer for the time out.

Jala answered 20/6, 2012 at 11:20 Comment(0)
A
4

Delete web.config file and insert again. http://forums.asp.net/post/916808.aspx

Aldrin answered 12/6, 2015 at 10:47 Comment(0)
W
2

Is your webservice configured correctly in IIS? The pool its using, the version of ASP.NET (2.0) is set? Can you browse the .asmx?

Talking about exceptions, try to put an try-catch block in the line that access your webservice. Put and catch(System.Web.Services.Protocolos.SoapException).

Also, you can set a Timeout for your webservice object.

Waldrop answered 4/8, 2009 at 14:52 Comment(1)
@Gustavo: StackOverflow has just turned one year old! The question you just answered is almost that old. Also, if you read the entire question and all the answers, you'll see that there's no way to catch this on the client, since it never gets to the client. I'm going to have to give you a downvote because your answer is not helpful. I hope this does not discourage you from trying to help.Benyamin
A
2

I had got this error after changing the web service return type and SoapDocumentMethod.

Initially it was:

[WebMethod]
public int Foo()
{
    return 0;
}

I decided to make it fire and forget type like this:

[SoapDocumentMethod(OneWay = true)]
[WebMethod]
public void Foo()
{
    return;
}

In such cases, updating the web reference helped.

To update a web service reference:

  • Expand solution explorer
  • Locate Web References - this will be visible only if you have added a web service reference in your project
  • Right click and click update web reference
Alexi answered 24/11, 2015 at 12:3 Comment(0)
T
1

The problem I had was related to SOAP version. The asmx service was configured to accept both versions, 1.1 and 1.2, so, I think that when you are consuming the service, the client or the server doesn't know what version resolve.

To fix that, is necessary add:

using (wsWebService yourService = new wsWebService())
{
    yourService.Url = "https://myUrlService.com/wsWebService.asmx?op=someOption";
    yourService.UseDefaultCredentials = true; // this line depends on your authentication type
    yourService.SoapVersion = SoapProtocolVersion.Soap11; // asign the version of SOAP
    var result = yourService.SomeMethod("Parameter");
}

Where wsWebService is the name of the class generated as a reference.

Tori answered 15/8, 2018 at 20:51 Comment(0)
T
0

Got it! For some reason my web service project had been configured on certain builds to output to bin\[Configuration] rather than just bin. As a result, the ASMX file being used (the one directly under bin) wasn't the one under source control and was resulting in an underlying Could not create type error (which could be seen on the yellow screen of death only if navigated-to via a web browser (e.g. http://localhost:12345/MyWebService.asmx)).

The top answer here explained about web service project's output path having to be just bin and nothing more: Web service Parser Error Message: Could not create type 'xxx'

Theorist answered 9/4 at 9:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.