Sunday, March 27, 2011

Client found response content type of 'text/html', but expected 'text/xml'

I am getting this error:

Client found response content type of 'text/html', but expected 'text/xml.

I am adding web reference for live search. When i build the project its Successful. But after that once i enter some text in textbox & enter search button it gives this error. I am Using my local machine & Using .net 2.0 with C#.
Plz help me...
Thanks In Advance...

From stackoverflow
  • Generally that error means that the service has sent back an (HTML) error message rather than the XML SOAP response that your client was expecting.

    For web services that you control it's really easy to find the problem, because you can invoke the webmethods by hand in your browser. To diagnose it when it's someone else's service is a little trickier. You might be able to trace into the code for your web reference and inspect the text of the response before the exception is thrown.

  • Thanks Matt...In my web project i am adding live search reference i.e http://soap.search.msn.com/webservices.asmx?wsdl.....& in cs file on Searchbutton click event i am using this code

            MSNSearchService s = new MSNSearchService();
            SearchRequest searchRequest = new SearchRequest();
            int arraySize = 1;
            SourceRequest[] sr = new SourceRequest[arraySize];
    
            sr[0] = new SourceRequest();
            sr[0].Source = SourceType.Web;
    
            searchRequest.Query = TextBox1.Text;
            searchRequest.Requests = sr;
            searchRequest.AppID = "APP ID you generated from http://search.msn.com/developer";///Here I am Putting my App code Id
            searchRequest.CultureInfo = "en-US";
            SearchResponse searchResponse;
    
            **searchResponse = s.Search(searchRequest); //Error comes on This line**
    
            foreach (SourceResponse sourceResponse in searchResponse.Responses)
            {
                Result[] sourceResults = sourceResponse.Results;
                if (sourceResponse.Total > 0)
                {
                    Label1.Text = sourceResponse.Source.ToString() + " - Total Results: " + sourceResponse.Total.ToString();
                }
                GridView1.DataSource = sourceResults;
                GridView1.DataBind();
    

    ....Plz give me some idea for that

    marshall : That link seems to be returning xml if you check it in firefox (right click - Page info). If you have a different url however it's probably returning a 404 or 500 which will be text not xml so check the url is all good.
  • As Matt said, it's probably an error page coming back.

    Either use a proxy like Fiddler or a network sniffer like WireShark to see what the raw response is - that should help you get to the bottom of what's going on.

  • Thanks Jon...But i am still not find any clue..Is this error is coming due to some proxy settings or IIS settings.

    I have downloaded CSharp Live Search Samples from http://www.microsoft.com/downloads and put the above code there but it is still giving the same error. Plz guide me if any one have any clue... Thanks.

  • In your actual code, did you replace the line:

    searchRequest.AppID = "APP ID you generated from ...";

    with the actual AppID, which should be a long alpha-numeric sequence?

    thanks, chris

  • Yes Chris I am putting the actual AppId That i got from msn developers center but the problem is same.... Thanks,Pranesh

  • I have found Fiddler to be highly useful in debugging http client server issues. It is a proxy that allows you to intercept and even change the content of the request and response.

  • Hi Chris, I have checked it in Fiddler & posting here the relevant data for failing item.... The failing URL is http://soap.search.live.com/webservices.asmx and session is POST /webservices.asmx HTTP/1.1 User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol 2.0.50727.42) VsDebuggerCausalityData: uIDPoyZkAPufYSdMn1HUvNBbIJ8AAAAAHyrV9wKwwUS9PBXv3XtLtWYLJXhC/MtCh6Yd8JPvdRgACAAA Content-Type: text/xml; charset=utf-8 SOAPAction: "http://schemas.microsoft.com/MSNSearch/2005/09/fex/Search" Host: soap.search.live.com Content-Length: 655 Expect: 100-continue Proxy-Connection: Keep-Alive

    ---------I have remove the App Id from here----------------------aspen-USModerateNoneWeb010Title Description Url

    Plz send me your suggestion or write me if u want any more Info.........

    Thanks

0 comments:

Post a Comment