【问题标题】:WCF http binding error: The content type text/html does not match the content type of the binding (text/xml; charset=utf-8)WCF http 绑定错误:内容类型 text/html 与绑定的内容类型不匹配 (text/xml; charset=utf-8)
【发布时间】:2015-03-02 11:21:33
【问题描述】:

我有一个 WPF 客户端,它使用一个 WCF 服务,该服务自托管在一个 Winforms 应用程序中。客户端通过 VPN 连接访问服务服务器。在第一次初始化时,客户端应用程序从服务中捕获了一个异常:

There was a problem reaching the service. 
The content type of 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.

该服务运行没有问题,并且此问题仅在通过 VPN 连接时出现,而不是来自与服务 VM 位于同一域的我的 Visual Studio 开发环境:

此异常仅在第一次初始化时发生,当我再次运行客户端应用程序时,问题已解决并且一切都按预期运行。这是我的服务应用配置:

  <services>
  <service name="IsesService.IsesService">                           
    <endpoint address="" binding="basicHttpBinding" contract="IsesService.IIsesService" bindingConfiguration="basicHttp">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>     
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="http://EMEA-DIIS01v:8082"/>
      </baseAddresses>
    </host>
  </service>
</services>

 <behavior>         
      <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True" />
      <dataContractSerializer maxItemsInObjectGraph="2147483646" />          
      <serviceDebug includeExceptionDetailInFaults="False" />
    </behavior>

 <bindings>
  <basicHttpBinding>
    <binding name="basicHttp"
             useDefaultWebProxy="false"
             maxReceivedMessageSize="2147483647" 
             maxBufferSize="2147483647"
             maxBufferPoolSize="2147483647"
              >
      <readerQuotas maxArrayLength="2147483647"
                maxBytesPerRead="2147483647"
                maxDepth="2147483647"
                maxNameTableCharCount="2147483647"
                maxStringContentLength="2147483647"/>      
    </binding>
  </basicHttpBinding>
</bindings>

和客户端:

  <system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_IIsesService" useDefaultWebProxy="false"
             maxReceivedMessageSize="2147483647"
             maxBufferSize="2147483647"
             maxBufferPoolSize="2147483647">
              <readerQuotas maxArrayLength="2147483647"
                        maxBytesPerRead="2147483647"
                        maxDepth="2147483647"
                        maxNameTableCharCount="2147483647"
                        maxStringContentLength="2147483647"/>
            </binding>
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://emea-diis01v:8082/" binding="basicHttpBinding"
            bindingConfiguration="BasicHttpBinding_IIsesService" contract="ServiceReference.IIsesService"
            name="BasicHttpBinding_IIsesService" />
    </client>      
</system.serviceModel>

我在这里遗漏了一些简单的东西吗?

【问题讨论】:

    标签: c# wpf wcf


    【解决方案1】:

    检查fiddler 第一个响应的内容是什么。 使用 VPN 时可能会有所不同。

    【讨论】:

    • 不幸的是,在浏览器中没有从 Fiddler 得到任何东西。我在 WCF 服务上启用了跟踪日志记录,但它没有记录问题,只是在它退出之前记录最后一次成功的方法调用。我认为这是一个与 VPN 相关的问题,超出了 .NET 代码的范围。
    猜你喜欢
    • 2011-07-12
    • 1970-01-01
    • 2015-03-02
    • 2023-03-30
    • 2017-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多