WCF 16384最大阵列长度

时间:2011-12-22 09:14:31

标签: arrays wcf exception

一直试图解决这个问题。我无法看到我的代码发现任何错误,请帮忙。谢谢! 我正在使用IIS来托管服务并使用添加服务引用作为客户端。 我确保添加了readerquota并更正了绑定配置。但是,当我发送大小超过16384kb的图像文件时,会发生错误。

Server
<?xml version="1.0"?>
<configuration>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_ICotfServerWCF" closeTimeout="00:01:00"
         openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
         allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
         maxBufferSize="20000000" maxBufferPoolSize="20000000" maxReceivedMessageSize="20000000"
         messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
         useDefaultWebProxy="true">
          <readerQuotas maxDepth="32"
      maxStringContentLength="5242880"
      maxArrayLength="2147483646"
      maxBytesPerRead="4096"
      maxNameTableCharCount="5242880" />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None"
             realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
      <service name="ServerWCF.ICotfServerWCF">
        <endpoint address="http://192.168.2.140:8081/CotfServerWCF.svc" binding="basicHttpBinding" behaviorConfiguration="filebehavior" name="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ICotfServerWCF" contract="ServerWCF.ICotfServerWCF" />
      </service>
    </services>



    <behaviors>
      <endpointBehaviors>
        <behavior name="filebehavior">
          <dataContractSerializer maxItemsInObjectGraph="2000000000"/>
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

  <connectionStrings>
    <add name="databaseCS" connectionString="Data Source=(local);Initial Catalog=CotfDatabase;User ID=CotfDbUser; Password=$ing1234;"/>
  </connectionStrings>
</configuration>



Client
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_Client" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferSize="6553600" maxBufferPoolSize="5242880" maxReceivedMessageSize="6553600"
                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                    useDefaultWebProxy="true">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="100000"
                        maxBytesPerRead="4096" maxNameTableCharCount="100000" />
                    <security mode="None">
                        <transport clientCredentialType="None" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
          <endpoint address="http://192.168.2.140:8081/CotfServerWCF.svc"
              binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_Client"
              contract="ServerWCF.ICotfServerWCF" name="BasicHttpBinding_ICotfServerWCF" >
          </endpoint>
        </client>
    </system.serviceModel>


</configuration>

在我将服务器和客户端更新为正确的值和正确的绑定后,我已经找到了问题。我的客户端仍在发送默认配置。此外,configuration.svcinfo文件仍处于默认值且未更新。有什么想法吗?

3 个答案:

答案 0 :(得分:0)

您是否更改了配置服务器和客户端配置。

答案 1 :(得分:0)

首先,您确定已将HttpRuntime设置为大于4MB。你可以这样做:

<httpRuntime maxRequestLength="1572864"/>

上面的元素在system.web元素下。 .NET框架的http运行时默认情况下不允许超过4MB的数据。

您在服务器和客户端上的读者配额有点不同。确保客户端读取器配额与服务器配额相同。

如果您有上述内容但仍然遇到问题,请尝试启用对您服务的跟踪,并告知您请求失败的确切原因。要启用跟踪,请参阅文章here

答案 2 :(得分:0)

客户端还应该获得一个设置maxItemsInObjectGraph

的behaviorConfiguration
<system.serviceModel>
  <behaviors>
    <endpointBehaviors>
      <behavior name="ServiceBehavior">
        <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
      </behavior>
    </endpointBehaviors>
  </behaviors>

然后..在您的客户端端点上引用此新行为...

<endpoint address="http://youraddresshere"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService"
            contract="" name="" behaviorConfiguration="ServiceBehavior" />

您还可以尝试在客户端和服务设置中增加maxBytesPerRead=""值。