Dot-Net

Silverlight+WCF 異常:期望應用程序/soap+xml,收到文本/xml

  • April 4, 2012

我有一個 Silverlight 應用程序,我想在其中呼叫 WCF 服務。呼叫服務時,我從伺服器收到以下響應:

415 無法處理消息,因為內容類型為 ’text/xml; charset=utf-8’ 不是預期的類型 ‘application/soap+xml; 字元集=utf-8

有沒有人遇到過這個問題?有誰知道我需要調整哪些配置設置?任何有關如何解決此問題的資訊將不勝感激。

那麼,您可以嘗試在VS2008中使用“Silverlight-enabled WCF Service”模板,並比較差異?我希望您需要使用basicHttpBinding並且正在使用更具異國情調的東西。

有關資訊,這是預設 Silverlight/WCF 服務的 web.config 部分:

<system.serviceModel>
 <behaviors>
  <serviceBehaviors>
   <behavior name="MySite.Service1Behavior">
    <serviceMetadata httpGetEnabled="true" />
    <serviceDebug includeExceptionDetailInFaults="false" />
   </behavior>
  </serviceBehaviors>
 </behaviors>
 <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
 <services>
  <service behaviorConfiguration="MySite.Service1Behavior"
      name="MySite.Service1">
   <endpoint address="" binding="basicHttpBinding"
      contract="MySite.Service1" />
   <endpoint address="mex" binding="mexHttpBinding"
      contract="IMetadataExchange" />
  </service>
 </services>
</system.serviceModel>

引用自:https://stackoverflow.com/questions/493883