readerQuotas maxStringContentLength没有改变

时间:2014-03-24 05:40:54

标签: wcf

我尝试了很多但没有成功,

我已将我的WinForms以及WCF配置文件的readerQuotas maxStringContentLength更改为2147483647,但仍然将maxStringContentLength设置为8192

在WinForms或WCF服务上,任何正文都可以告诉我如何更改它以及在哪里进行更改。

客户端配置

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <connectionStrings>
    <add name="ConnectWiseEntities" connectionString="data source=deepak;initial catalog=ConnectWise;persist security info=True;user id=sa;password=weexcel;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IService" closeTimeout="00:01:00"
          openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
          allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
          maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
          messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
          useDefaultWebProxy="true">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647"
            maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None"
              realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:50841/SyncFile(WCF2)/Service.svc"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService"
        contract="SynWebService.IService" name="BasicHttpBinding_IService" />
    </client>
  </system.serviceModel>
</configuration>

WCF Web.config

<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0"/>
  </system.web>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IService" closeTimeout="00:01:00"
          openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
          allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
          maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
          messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
          useDefaultWebProxy="true">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647"
            maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None"
              realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <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="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

2 个答案:

答案 0 :(得分:2)

您的客户端配置似乎没问题,修改了您的服务配置并将相应的行为添加到服务中,如下所示。

您需要正确设置绑定和行为。右键单击您的Web配置并选择编辑WCF配置。

enter image description here 例如,

 <bindings>
      <basicHttpBinding>
        <binding name="defaultBinding">
          <readerQuotas maxStringContentLength="1048576" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
      <service name="Service1">
        <endpoint address="http://localhost:56529/Service1.svc" 
  binding="basicHttpBinding" bindingConfiguration="defaultBinding" 
  contract="IWebExtractServiceIWebExtractService">
        </endpoint>
      </service>
    </services>

答案 1 :(得分:0)

您已在服务的Web配置中定义了绑定配置,但您从未告诉服务使用它,因此使用了basicHttpBinding的默认值。

在WCF 4.0+中,你有两种方法可以做到这一点(Sajeethran给出了一个)。

您可以通过省略绑定配置上的name属性来定义绑定的配置并将其设置为服务的默认配置,如下所示:

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding closeTimeout="00:01:00" openTimeout="00:01:00" 
             receiveTimeout="00:10:00" sendTimeout="00:01:00"
             allowCookies="false" bypassProxyOnLocal="false"
             hostNameComparisonMode="StrongWildcard"
             maxBufferSize="2147483647" maxBufferPoolSize="2147483647"
             maxReceivedMessageSize="2147483647" messageEncoding="Text"
             textEncoding="utf-8" transferMode="Buffered"
             useDefaultWebProxy="true">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
                    maxArrayLength="2147483647" maxBytesPerRead="2147483647"
                    maxNameTableCharCount="2147483647" />
      <security mode="None">
        <transport clientCredentialType="None" proxyCredentialType="None"
                   realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>
  </basicHttpBinding>
</bindings>

由于省略了name属性,因此使用此配置的任何服务都将使用上述绑定配置作为来自http协议的请求的默认值,除非在特定端点元素中覆盖{ {1}}属性。

第二种方法是明确定义一个端点,并为bindingCongifuration属性分配你定义的绑定配置的名称(再次如Sajeetharan的回答所示)。