请求超过4MB时,WCF服务返回HTML

时间:2013-09-20 02:24:37

标签: c# wcf silverlight

从我的客户端silverlight应用程序调用我的WCF服务,我有时会收到ProtocolException:

  

内容类型text / html; charset =响应消息的UTF-8与绑定的内容类型不匹配(text / xml; charset = utf-8)。

通常,我可以进入WCF服务代码并看到它构建一个对象,然后以序列化形式返回它。

但是当请求超过〜4MB(由Fiddler2报告)时,WCF服务代码中的断点未被命中,响应的内容(序列化对象应该在哪里)是标准HTML页面的HTML看看你是否浏览了这项服务 - 看起来像这样:

Service intro page

我可以通过在请求对象图中的字符串中随机添加字符,或者从图中删除块来使任何请求失败或成功,所以我非常有信心这是关于请求的大小。

如果有人能够解释为什么回复包含HTML ,我将非常感激,如果您能告诉我如何修复它,我将非常感激。

我正在使用VS2010。我的服务器端配置是:

<httpRuntime executionTimeout="10800"
               maxRequestLength="10240" />

...

<system.web>
    <httpRuntime maxRequestLength="2147483647" />
</system.web>

...

<serviceBehaviors>
    <behavior name="StandardServiceBehavior">
        <serviceMetadata httpGetEnabled="true"/>
        <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>
</serviceBehaviors>

...

<binding name="BasicHttpBinding_SilverlightService"
         useDefaultWebProxy="false"
         transferMode="Streamed"
         bypassProxyOnLocal="true"
         receiveTimeout="00:20:00"
         sendTimeout="00:20:00"
         maxBufferSize="2147483647"
         maxReceivedMessageSize="2147483647"
         maxBufferPoolSize="2147483647">
    <readerQuotas maxStringContentLength="2147483647"
                  maxArrayLength="2147483647"
                  maxBytesPerRead="2147483647"
                  maxDepth="2147483647"
                  maxNameTableCharCount="2147483647"/>
    <security mode="TransportCredentialOnly">
        <transport clientCredentialType="None"/>
    </security>
</binding>

客户端我有:

<binding name="BasicHttpBinding_SilverlightService" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
    <security mode="None" />
</binding>

更新

我也尝试从this post建议的绑定标记中删除名称。

1 个答案:

答案 0 :(得分:1)

你看过这篇文章了吗?

http://smehrozalam.wordpress.com/2009/01/29/retrieving-huge-amount-of-data-from-wcf-service-in-silverlight-application/

你显然已经覆盖了dataContractSerializer部分,只是想知道是否还缺少其他任何内容。