Silverlight + WCF异常:期待application/soap + xml,收到text/xml

Kev*_*vin 12 .net silverlight wcf exception-handling wcf-configuration

我有一个Silverlight应用程序,我想在其中调用WCF服务.在调用服务时,我从服务器收到以下响应:

415无法处理消息,因为内容类型为'text/xml; charset = utf-8'不是预期的类型'application/soap + xml; 字符集= utf-8的

以前有没有人遇到过这个问题?有谁知道我需要调整哪些配置设置?任何有关如何解决这个问题的信息将不胜感激.

Mar*_*ell 9

那么,您可以尝试使用VS2008中的"支持Silverlight的WCF服务"模板,并比较差异?我希望你需要使用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>
Run Code Online (Sandbox Code Playgroud)