Expecting "text/xml" and getting "text/xml" + utf-8 encoding

Expecting "text/xml" and getting "text/xml" + utf-8 encoding

Post by MD » Wed, 29 Mar 2006 03:02:00



Hello, the code at the bottom of this post is attempting to consume a
web service - the consumer is running on an Windows Server 2003 IIS
machine - nothing that remarkable in that up until recently it was
working fine, however when we applied a Windows patch (not sure which
one), it falls over and the web service returns (as per the event log)
:-

Exception Type: System.InvalidOperationException
Message: Client found response content type of ': text/xml;
charset="UTF-8"', but expected 'text/xml'.
The request failed with the error message:
--
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd3="http://www.w3.org/2001/XMLSchema"
xmlns:xsi3="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Body>
<searchResponse SOAP-ENC:root="1">
<ns1:searchResponsePart
xmlns:ns1="http://verity.com/service/2003/search">
<totalHits xsi3:type="xsd3:long">0</totalHits>
<totalHitsIsExact xsi3:type="xsd3:boolean">false</totalHitsIsExact>
...
</item>
</longAttributes>
<stringAttributes SOAP-ENC:arrayType="ns1:StringParameter[0]"
xsi3:type="SOAP-ENC:Array">
</stringAttributes>
</ns1:searchResponsePart>
</searchResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
--.
TargetSite: System.Object[]
ReadResponse(System.Web.Services.Protocols.SoapClientMessage,
System.Net.WebResponse, System.IO.Stream, Boolean)
HelpLink: NULL
Source: System.Web.Services

StackTrace Information
*********************************************
   at
System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage
message, WebResponse response, Stream responseStream, Boolean
asyncCall)
   at
System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String
methodName, Object[] parameters)
   at
Prudential.CorporateIT.GroupIntranet.Presentation.Search.carmeintgrouplocal8765.search(SearchRequestMessage
searchRequestPart) in g:\projects\groupintranet\presentation\web
references\search\reference.cs:line 89
   at
Prudential.CorporateIT.GroupIntranet.Presentation.Templates.Search.SearchQuery(String
Input, String searchQuery, Boolean bindData) in
g:\projects\groupintranet\presentation\templates\search.aspx.cs:line
455

The code is as follows :-

Reference.cs
==========

    public class carmeintgrouplocal8765 :
System.Web.Services.Protocols.SoapHttpClientProtocol {
    ....
    }

    [System.Xml.Serialization.SoapTypeAttribute("SearchRequestMessage",
"http://verity.com/service/2003/search")]
    public class SearchRequestMessage {

        /// <remarks/>
        public string[] sources;

        /// <remarks/>
        public string query;

        /// <remarks/>
        public string querySyntax;

        /// <remarks/>
        public string locale;

        /// <remarks/>
        public long startResult;

        /// <remarks/>
        public long numberOfResults;

        /// <remarks/>
        public BooleanParameter[] booleanParameters;

        /// <remarks/>
        public DateParameter[] dateParameters;

        /// <remarks/>
        public DoubleParameter[] doubleParameters;

        /// <remarks/>
        public LongParameter[] longParameters;

        /// <remarks/>
        public StringParameter[] stringParameters;
    }

[System.Xml.Serialization.SoapTypeAttribute("SearchResponseMessage",
"http://verity.com/service/2003/search")]
    public class SearchResponseMessage {

        /// <remarks/>
        public long totalHits;

        /// <remarks/>
        public bool totalHitsIsExact;

        /// <remarks/>
        public SourceInfo[] sourceInfo;

        /// <remarks/>
        public Result[] results;

        /// <remarks/>
        public BooleanParameter[] booleanAttributes;

        /// <remarks/>
        public DateParameter[] dateAttributes;

        /// <remarks/>
        public DoubleParameter[] doubleAttributes;

        /// <remarks/>
        public LongParameter[] longAttributes;

        /// <remarks/>
        public StringParameter[] stringAttributes;
    }

consumews.cs
===========

...
carmeintgrouplocal8765 service = new carmeintgrouplocal8765();
SearchRequestMessage request = new SearchRequestMessage();
SearchResponseMessage response = null;
response = service.search(request);
...

Most of the newsgroup entries complain about falling over because they
expect "text/xml" but get "text/html" - this is very often because
something has happened at the web service end and it is trying to
return an error message in html format - however this is different as
here I am expecting "text/xml" and I get "text/xml" with "utf-8"
encoding.

Is there anything I can do to either make my response object
(SearchResponseMessage class above) cater for the utf-8 encoding OR for
me to make sure the message I receive does not contain the utf-8
encoding.

Any ideas would be much appreciated ?

Cheers
Travis