Webservice returns wrong content-type response header
Asked Answered
P

2

0

I am trying to use third-party web service (php-based) in asp.net c# application, and failed with service configuration.Already tried add service/web reference - all the same error :

The content type text/html of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 402 bytes of the response were: '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body>;<...

[Response was edited manually to correctly display > < chars, it's perfectly valid otherwise]

To me it seems like a perfectly valid response, and I tried to look at what fiddler writes in response headers - Content-Type: text/html, which is probably the source of issue - webservice sents wrong content-type (text/html instead of text/xml) , but how to configure my client to ignore/override received content-type ? Googling gets me nothing so please, if anyone could help - where problem is? Binding\endpoint configuration is a default basicHttpBinding/endpoint which is generated by VS2010 when using Add Service Reference option, nothing was changed there. Thanks in advance.

[app.config]

<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup  name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0,      Culture=neutral, PublicKeyToken=b77a5c561934e089">
  <section name="Collection.ServicePlayground.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
</sectionGroup>
</configSections>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="SmsServiceSoap1" closeTimeout="00:01:00" openTimeout="00:01:00"
    receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
    bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
    maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
    useDefaultWebProxy="true">
    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
    <security mode="None">
    transport clientCredentialType="None" proxyCredentialType="None"
    realm="" />
    <message clientCredentialType="UserName" algorithmSuite="Default" />
    </security>
    </binding>
  </basicHttpBinding>
</bindings>
<client>
  <endpoint address="http://ws1.streamsms.ru/SmsService.php" binding="basicHttpBinding"
    bindingConfiguration="SmsServiceSoap1" contract="SmsService.SmsServiceSoap"
    name="SmsServiceSoap2" />
</client>
</system.serviceModel>
<applicationSettings>
<Collection.ServicePlayground.Properties.Settings>
  <setting name="Collection_ServicePlayground_WSStreamProvider_SmsService"   serializeAs="String">
    <value>http://ws1.streamsms.ru/SmsService.php</value>
  </setting>
 </Collection.ServicePlayground.Properties.Settings>
 </applicationSettings>
 </configuration>
Patron answered 21/6, 2012 at 9:35 Comment(4)
Are you sure that the service is using basicHttpBinding? Can you access the wsdl? Sounds like a binding mismatch between client and service.Santamaria
I can access WSDL but it gives me nothing new about binding :(. It's definitely binding problem - custom ws test tool (soapUI) works perfectly with service, and the issue is that response header from service contains ContentType:text/html which is just plain wrong - response content is perfectly valid soap/xml. I just dont get how to configure my binding/endpoint to not take that header seriously :)Patron
BTW, may be it can shed some light, web service is php-based, and basicHttpBinding was created by vs2010-option "Add Service Reference".Patron
Can you post your .config file?Santamaria
S
1

Perhaps overkill, but you could try with a custom encoder for the binding. Default is text/xml.

http://msdn.microsoft.com/en-us/library/ms751486.aspx

Santamaria answered 21/6, 2012 at 21:3 Comment(2)
I agree. I think blogs.msdn.com/b/nathana/archive/2011/04/05/… has a good explanation of building just such a thing as well.Equilateral
You probably right, thanks for your effort. Seems a little weird to me, but for sure it's more that particular webservice fail , not a WCF one.Patron
E
1

I am not sure but do you think you are running into what is shown here: http://cushen.wordpress.com/2009/04/08/web-service-content-type-error-using-visual-studio-2008/

Seems pretty similar.. You should use Add Web Reference vs Add Service Reference (since the latter is for WCF style services?)

Maybe.. :)

Equilateral answered 21/6, 2012 at 11:9 Comment(4)
Tried before posting here - the same exception, but in another wrapping (in wcf case it's ProtocolException, if using a web-reference thing its InvalidOperationException with the same message as was first one)Patron
Can you check if the xml string has the Byte order Mark for the UTF-8 string? That might cause this issue.Equilateral
Not sure if I get that correctly. I can read xml value from request and check it for BOM, but its not clear for me what can be done with it then :) Also whole thing works pretty well in SoapUI and another third party web-service-calling tool without any additional setupPatron
I had issues with that BOM not being there made the parser not read the content correctly. That was what i was hoping for. :(Equilateral
S
1

Perhaps overkill, but you could try with a custom encoder for the binding. Default is text/xml.

http://msdn.microsoft.com/en-us/library/ms751486.aspx

Santamaria answered 21/6, 2012 at 21:3 Comment(2)
I agree. I think blogs.msdn.com/b/nathana/archive/2011/04/05/… has a good explanation of building just such a thing as well.Equilateral
You probably right, thanks for your effort. Seems a little weird to me, but for sure it's more that particular webservice fail , not a WCF one.Patron

© 2022 - 2024 — McMap. All rights reserved.