鸿 网 互 联 www.68idc.cn

当前位置 : 服务器租用 > .net技术 > wcf编程 > >

WCF 配置文件中的MaxStringContentLength MaxReceivedMessageSize

来源:互联网 作者:佚名 时间:2013-12-23 17:04
中午测试员在测试系统模块时发现无法通过 WCF 从服务器下载数据,检查配置文件后,建议开发人员修改站点的 WEB.CONFIG 文件,具体修改对比如下: 旧的: binding closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00

中午测试员在测试系统模块时发现无法通过WCF服务器下载数据,检查配置文件后,建议开发人员修改站点的WEB.CONFIG文件,具体修改对比如下:

旧的:

<binding closeTimeout="00:01:00"

          openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"

          allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"

          maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"

          messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"

          useDefaultWebProxy="true">

          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"

            maxBytesPerRead="4096" maxNameTableCharCount="16384" />

          <security mode="None">

            <transport clientCredentialType="None" proxyCredentialType="None"

              realm="" />

            <message clientCredentialType="UserName" algorithmSuite="Default" />

          </security>

</binding>

 

新的:

<binding closeTimeout="00:01:00"

          openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"

          allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"

          maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="9223372036854775807"

          messageEncoding="Text" textEncoding="utf-8" transferMode="Streamed"

          useDefaultWebProxy="true">

          <readerQuotas maxDepth="6553500" maxStringContentLength="2147483647"

            maxArrayLength="6553500" maxBytesPerRead="6553500" maxNameTableCharCount="6553500" />

          <security mode="None">

            <transport clientCredentialType="None" proxyCredentialType="None"

              realm="" />

            <message clientCredentialType="UserName" algorithmSuite="Default" />

          </security>

</binding>

 

注意这里修改的主要是maxReceivedMessageSize这个属性,解决了从服务器通过WCF下载大容量数据的问题。

 

下午测试人员继续测试,发现无法将数据通过WCF保存回服务器端。检查数据后发现,需要被保存的数据超过9K,而WCF服务器端使用的是binding="basicHttpBinding"这个数据绑定方式。思路打开,,则应该是由于服务器端的接收的数据大小有限制。

当初次引用服务后,显示的服务器端binding="basicHttpBinding" 的最大上传数据容量是:

<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"

            maxBytesPerRead="4096" maxNameTableCharCount="16384" />

注意是maxStringContentLength="8192" ,那么判定,是由于绑定的默认值未被修改的缘故。接着修改服务器端的web.config配置文件。修改对比如下:

旧的:

<system.serviceModel>

    <behaviors>

      <serviceBehaviors>

        <behavior>

          <serviceMetadata httpGetEnabled="true" />

          <serviceDebug includeExceptionDetailInFaults="true" />

        </behavior>

        <behavior>

          <serviceMetadata httpGetEnabled="true"/>

          <serviceDebug includeExceptionDetailInFaults="true" />

        </behavior>

        <behavior>

          <serviceMetadata httpGetEnabled="true"/>

          <serviceDebug includeExceptionDetailInFaults="true" />

        </behavior>

        <behavior>

          <serviceMetadata httpGetEnabled="true"/>

          <serviceDebug includeExceptionDetailInFaults="true" />

        </behavior>

        <behavior>

          <serviceMetadata httpGetEnabled="true"/>

          <serviceDebug includeExceptionDetailInFaults="true" />

        </behavior>

        <behavior>

          <serviceMetadata httpGetEnabled="true"/>

          <serviceDebug includeExceptionDetailInFaults="true" />

        </behavior>

        <behavior>

          <serviceMetadata httpGetEnabled="true" />

          <serviceDebug includeExceptionDetailInFaults="true" />

        </behavior>

        <behavior>

          <serviceMetadata httpGetEnabled="true" />

          <serviceDebug includeExceptionDetailInFaults="true" />

        </behavior>

      </serviceBehaviors>

    </behaviors>

    <services>

      <service behaviorConfiguration="CVMTransactionCaseServiceBehavior">

        <endpoint address="" binding="basicHttpBinding" contract="CentaLine.CVM.Services.ICVMTransactionCaseService" />

        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />

      </service>

      <service behaviorConfiguration="AuthTaxTransactionInfoServiceBehavior">

        <endpoint address="" binding="basicHttpBinding" contract="CentaLine.CVM.Services.IAuthTaxTransactionInfoService"/>

      </service>

      <service behaviorConfiguration="DealingTransactionInfoServiceBehavior">

        <endpoint address="" binding="basicHttpBinding" contract="CentaLine.CVM.Services.IDealingTransactionInfoService"/>

      </service>

      <service behaviorConfiguration="HousePassTransactionInfoServiceBehavior">

        <endpoint address="" binding="basicHttpBinding" contract="CentaLine.CVM.Services.IHousePassTransactionInfoService"/>

      </service>

      <service behaviorConfiguration="PreAuthTransactionInfoServiceBehavior">

        <endpoint address="" binding="basicHttpBinding" contract="CentaLine.CVM.Services.IPreAuthTransactionInfoService"/>

      </service>

      <service behaviorConfiguration="PropertyApplyInfoServiceBehavior">

        <endpoint address="" binding="basicHttpBinding" contract="CentaLine.CVM.Services.IPropertyApplyInfoService"/>

      </service>

      <service behaviorConfiguration="CommonInfoServiceBehavior">

        <endpoint address="" binding="basicHttpBinding" contract="CentaLine.CVM.Services.ICommonInfoService"/>

      </service>

      <service behaviorConfiguration="CenterAssignServiceBehavior">

        <endpoint address="" binding="basicHttpBinding" contract="CentaLine.CVM.Services.ICenterAssignService"/>

      </service>

    </services>

  </system.serviceModel>

 

新的:

  <system.serviceModel>

      <!--<behaviors />-->

      <bindings>

          <basicHttpBinding>

              <binding name="NewBinding0" maxReceivedMessageSize="6553600">

                  <readerQuotas maxStringContentLength="6553600" />

              </binding>

          </basicHttpBinding>

      </bindings>

         

 

     

      <behaviors>

      <serviceBehaviors>

        <behavior name="CVMTransactionCaseServiceBehavior">

          <serviceMetadata httpGetEnabled="true" />

          <serviceDebug includeExceptionDetailInFaults="true" />

        </behavior>

        <behavior name="AuthTaxTransactionInfoServiceBehavior">

          <serviceMetadata httpGetEnabled="true"/>

          <serviceDebug includeExceptionDetailInFaults="true" />

        </behavior>

        <behavior name="DealingTransactionInfoServiceBehavior">

          <serviceMetadata httpGetEnabled="true"/>

          <serviceDebug includeExceptionDetailInFaults="true" />

        </behavior>

        <behavior name="HousePassTransactionInfoServiceBehavior">

          <serviceMetadata httpGetEnabled="true"/>

          <serviceDebug includeExceptionDetailInFaults="true" />

        </behavior>

        <behavior name="PreAuthTransactionInfoServiceBehavior">

          <serviceMetadata httpGetEnabled="true"/>

          <serviceDebug includeExceptionDetailInFaults="true" />

        </behavior>

        <behavior name="PropertyApplyInfoServiceBehavior">

          <serviceMetadata httpGetEnabled="true"/>

          <serviceDebug includeExceptionDetailInFaults="true" />

        </behavior>

        <behavior name="CommonInfoServiceBehavior">

          <serviceMetadata httpGetEnabled="true" />

          <serviceDebug includeExceptionDetailInFaults="true" />

        </behavior>

        <behavior name="CenterAssignServiceBehavior">

          <serviceMetadata httpGetEnabled="true" />

          <serviceDebug includeExceptionDetailInFaults="true" />

        </behavior>

      </serviceBehaviors>

    </behaviors>

    <services>

      <service name="CentaLine.CVM.Services.CVMTransactionCaseService"behaviorConfiguration="CVMTransactionCaseServiceBehavior">

网友评论
<