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

时间:2012-06-21 09:35:34

标签: c# wcf web-services wcf-configuration protocolexception

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

  

响应消息的内容类型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” ><皂:身体取代;< ...

[手动编辑响应以正确显示> < chars,否则完全有效]

对我而言,这似乎是一个非常有效的回应,我试着看看小提琴手在回复标题中写的内容 - Content-Type:text / html,可能是问题的根源 - webservice看错了内容类型(text / html而不是text / xml),但是如何配置我的客户端忽略/覆盖收到的内容类型?谷歌搜索没有给我什么,所以请,如果有人可以帮助 - 问题是什么? Binding \ endpoint配置是一个默认的basicHttpBinding / endpoint 由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>

2 个答案:

答案 0 :(得分:1)

我不确定,但你认为你遇到了这里显示的内容:http://cushen.wordpress.com/2009/04/08/web-service-content-type-error-using-visual-studio-2008/

看起来非常相似..您应该使用添加Web引用与添加服务引用(因为后者适用于WCF样式服务?)

也许.. :))

答案 1 :(得分:1)

也许是矫枉过正,但您可以尝试使用自定义编码器进行绑定。默认为text / xml。

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

相关问题