C# Webservice返回错误的内容类型响应头

C# Webservice返回错误的内容类型响应头,c#,wcf,web-services,wcf-configuration,protocolexception,C#,Wcf,Web Services,Wcf Configuration,Protocolexception,我试图在asp.net c#应用程序中使用第三方web服务(基于php),但服务配置失败。已尝试添加服务/web引用-所有相同错误: 响应消息的内容类型text/html与 绑定的内容类型(text/xml;charset=utf-8)。如果使用 自定义编码器,请确保IsContentTypeSupported方法 执行得当。响应的前402个字节是: '; < 查斯,否则完全有效] 对我来说,这似乎是一个完全有效的响应,我试图看看fiddler在响应头中写了什么- 内容类型:text/html,

我试图在asp.net c#应用程序中使用第三方web服务(基于php),但服务配置失败。已尝试添加服务/web引用-所有相同错误:

响应消息的内容类型text/html与 绑定的内容类型(text/xml;charset=utf-8)。如果使用 自定义编码器,请确保IsContentTypeSupported方法 执行得当。响应的前402个字节是: '; < 查斯,否则完全有效]

对我来说,这似乎是一个完全有效的响应,我试图看看fiddler在响应头中写了什么- 内容类型:text/html,这可能是问题的根源-webservice发送了错误的内容类型(text/html而不是text/xml),但是如何配置我的客户端来忽略/覆盖接收到的内容类型?谷歌搜索什么也帮不了我,所以,如果有人能帮忙的话——问题出在哪里?Binding\endpoint配置是默认的basicHttpBinding/endpoint,它 是由VS2010在使用添加服务引用选项时生成的,没有任何更改。 提前谢谢

[应用程序配置]

<?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>

transport clientCredentialType=“无”proxyCredentialType=“无”
realm=”“/>
http://ws1.streamsms.ru/SmsService.php

我不确定,但您是否认为您遇到了此处显示的问题:

似乎很相似。。您应该使用添加Web引用与添加服务引用(因为后者是用于WCF样式的服务?)


也许……)

可能有些过分,但您可以尝试使用自定义编码器进行绑定。默认值为text/xml


您确定服务正在使用basicHttpBinding吗?您可以访问wsdl吗?听起来客户端和服务之间的绑定不匹配。我可以访问WSDL,但它没有给我绑定方面的任何新信息:(。这肯定是绑定问题-自定义ws-test工具(soapUI)与服务完美配合,问题是服务的响应头包含ContentType:text/html,这完全是错误的-响应内容是完全有效的soap/xml。我只是不知道如何配置我的绑定/端点以不认真对待该头:)顺便说一句,这可能会有所帮助,web服务是基于php的,basicHttpBinding是由vs2010选项“添加服务引用”创建的。你能发布你的.config文件吗?在这里发布之前尝试过-相同的异常,但在另一个包装中(在wcf的情况下,它是ProtocolException,如果使用web引用,它的InvalidOperationException与第一个相同的消息)能否检查xml字符串是否具有UTF-8字符串的字节顺序标记?这可能会导致此问题。不确定我是否正确理解。我可以从请求中读取xml值并检查它的BOM表,但我不清楚如何使用它:)整个过程在SoapUI和另一个第三方web服务调用工具中运行得很好,没有任何附加设置。我遇到了BOM表不存在的问题,导致解析器无法正确读取内容。这就是我所希望的(我同意。我认为构建这样一个东西也有很好的解释。你可能是对的,谢谢你的努力。对我来说似乎有点奇怪,但可以肯定的是,更多的是特定的Web服务失败,而不是WCF失败。