【问题标题】:WCF 16384 max array lengthWCF 16384 最大数组长度
【发布时间】:2011-12-22 09:14:30
【问题描述】:

试图解决这个问题一天。我看不到我的代码有任何错误,请帮忙。谢谢! 我正在使用 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 文件仍为默认值且未更新。有什么想法吗?

【问题讨论】:

    标签: arrays wcf exception


    【解决方案1】:

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

    【讨论】:

    • 是的,我为服务器和客户端尝试了相同的值,也尝试了不同的值。尽管如此,它仍然没有工作。我设置的值都在16384以上,谢谢大家的帮助!
    • 嗨,我已经更新了我的问题,可以再看看吗?谢谢!
    【解决方案2】:

    首先,您确定您已将 HttpRuntime 设置为超过 4MB。如下图所示:

    <httpRuntime maxRequestLength="1572864"/>
    

    上述元素位于 system.web 元素下。 .NET 框架的 http 运行时默认不允许超过 4MB 的数据。

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

    完成上述操作后,您仍然遇到问题,然后尝试在您的服务上启用跟踪,它应该会告诉您请求失败的确切原因。要启用跟踪,请按照文章here

    【讨论】:

    • 一分钟我以为终于有了答案,可悲的是,它仍然不起作用。无论如何,跟踪异常显示:“System.ServiceModel.ProtocolException,System.ServiceModel,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089”消息:“远程服务器返回意外响应:(400)错误请求。”实际上并没有真正的帮助。 :\
    • 如果您深入跟踪文件,您应该会找到错误请求的原因。您也可以发布您的服务合同和您正在发布的请求。尝试使用 fiddler 来捕获您的请求。 (希望您已更新客户端配置,使其具有与服务器相同的读取器配额)
    • 您好,我已经在服务器上更新并再次使用了跟踪。我发现:已超出传入邮件的最大邮件大小配额 (65536)。要增加配额,请在适当的绑定元素上使用 MaxReceivedMessageSize 属性。
    • 好像你的客户在绑定元素中有这个。只需尝试将其增加到与服务器上相同的值即可。
    • 在上面发布的配置中,值是不同的。
    【解决方案3】:

    客户端还应该获得一个设置 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="" 值。

    【讨论】:

      猜你喜欢
      • 2011-03-05
      • 1970-01-01
      • 2012-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多