web服务返回错误的内容类型响应头 [英] Webservice returns wrong content-type response header
问题描述
我想在asp.net C#应用程序中使用第三方的Web服务(基于PHP),并与服务configuration.Already失败尝试添加服务/ Web引用 - 所有相同的错误:
响应消息的内容类型text / html不匹配绑定的
的内容类型(文本/ XML的,字符集= UTF-8) 。如果使用
定制的编码器,确保IsContentTypeSupported方法正确实现
。第一402字节的响应为:
'&下; XML版本=1.0编码=UTF-8>&下;肥皂:?信封
的xmlns:皂=HTTP:// schemas.xmlsoap.org/soap/envelope/
的xmlns:XSI =http://www.w3.org/2001/XMLSchema-instance
的xmlns:XSD =HTTP:// WWW .w3.org / 2001 / XML模式><肥皂:车身>;< ...
块引用>
[回应是手动编辑要正确显示><字符,这是完全有效的,否则]
要我来说,这似乎是一个完全有效的反应,我想看看什么小提琴手在响应报头写 -
含量型:text / html的,这可能是问题的根源 - webservice的货物内错误的内容类型(文本/ HTML而不是文本/ XML),但如何配置我的客户忽略/覆盖接收的内容类型?谷歌搜索得到我什么,所以请,如果有人可以帮助 - 在问题是什么? Binding\endpoint配置是默认basicHttpBinding的/端点其中
使用时添加服务引用选项,通过VS2010生成,什么也没有改变那里。
先谢谢了。
[app.config中]
<?XML版本=1.0>?;
<结构>
< configSections>
< sectionGroup名=的applicationSettingsTYPE =System.Configuration.ApplicationSettingsGroup,系统,版本= 4.0.0.0,文化=中性公钥= b77a5c561934e089>
<节名称=Collection.ServicePlayground.Properties.SettingsTYPE =System.Configuration.ClientSettingsSection,系统,版本= 4.0.0.0,文化=中性公钥= b77a5c561934e089requirePermission =FALSE/> ;
< / sectionGroup>
< / configSections>
< system.serviceModel>
<&绑定GT;
<&basicHttpBinding的GT;
<绑定名称=SmsServiceSoap1closeTimeout =00:01:00openTimeout =00:01:00
receiveTimeout =00:10:00的SendTimeout =00:01: 00allowCookies =false的
bypassProxyOnLocal =假hostNameComparisonMode =StrongWildcard
MAXBUFFERSIZE =65536maxBufferPoolSize =524288maxReceivedMessageSize =65536
messageEncoding =TEXTtextEncoding =UTF-8transferMode =缓冲
useDefaultWebProxy =真正的>
< readerQuotas MAXDEPTH =32maxStringContentLength =8192maxArrayLength =16384
maxBytesPerRead =4096maxNameTableCharCount =16384/>
<安全模式=无>
运输clientCredentialType =无proxyCredentialType =无
境界=/>
<消息clientCredentialType =用户名algorithmSuite =默认/>
< /安全>
< /&结合GT;
< / basicHttpBinding的>
< /绑定>
<客户端>
<端点地址=http://ws1.streamsms.ru/SmsService.php绑定=basicHttpBinding的
bindingConfiguration =SmsServiceSoap1合同=SmsService.SmsServiceSoap
名称=SmsServiceSoap2/>
< /客户>
< /system.serviceModel>
<&的applicationSettings GT;
< Collection.ServicePlayground.Properties.Settings>
<设定名=Collection_ServicePlayground_WSStreamProvider_SmsServiceserializeAs =字符串>
< VALUE> HTTP://ws1.streamsms.ru/SmsService.php< /值>
< /设置>
< /Collection.ServicePlayground.Properties.Settings>
< /&的applicationSettings GT;
< /结构>
解决方案或许矫枉过正,但你可以使用自定义的编码器试试为结合。默认为text / xml。
的 http://msdn.microsoft.com/en-us/library/ms751486.aspx
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>
解决方案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
这篇关于web服务返回错误的内容类型响应头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!