C# Web 服务返回错误的内容类型响应标头
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11135392/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Webservice returns wrong content-type response header
提问by tbd
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 :
我正在尝试在 asp.net c# 应用程序中使用第三方 web 服务(基于 php),但服务配置失败。已经尝试添加服务/web 引用 - 所有相同的错误:
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>;<...
响应消息的内容类型 text/html 与绑定的内容类型 (text/xml; charset=utf-8) 不匹配。如果使用自定义编码器,请确保正确实现 IsContentTypeSupported 方法。响应的前 402 个字节是:'<?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.
对我来说,这似乎是一个完全有效的响应,我试图查看 fiddler 在响应标头中写入的内容 - Content-Type: text/html,这可能是问题的根源 - webservice 发送了错误的内容类型(而不是 text/html的 text/xml) ,但如何配置我的客户端忽略/覆盖收到的内容类型?谷歌搜索对我没有任何帮助,如果有人可以提供帮助 - 问题出在哪里?Binding\endpoint 配置是默认的 basicHttpBinding/endpoint,它是在使用 Add Service Reference 选项时由 VS2010 生成的,那里没有任何更改。提前致谢。
[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>
采纳答案by Jocke
Perhaps overkill, but you could try with a custom encoder for the binding. Default is text/xml.
也许矫枉过正,但您可以尝试使用自定义编码器进行绑定。默认为文本/xml。
回答by gbvb
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/
我不确定,但您是否认为您遇到了此处显示的内容: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?)
看起来很相似..您应该使用添加 Web 引用与添加服务引用(因为后者用于 WCF 样式服务?)
Maybe.. :)
也许.. :)

