WCF: maxStringContentLength always set to 8192

前端 未结 2 762
难免孤独
难免孤独 2020-12-30 04:53

I need to change the maxStringContentLength to a value larger than 8192 but have not been successful in doing it. My WCF service will generate an exception if the amount of

相关标签:
2条回答
  • 2020-12-30 05:30

    update your client side config too. Set Reader's quota in and its attributes in the binding section.

    0 讨论(0)
  • 2020-12-30 05:42

    By default, the latest version of WCF does in fact setup defaults and json is the default. What wasn't clear was what kind of default binding WCF was using. It turns out to be webHttpBinding. You will also see a ton of examples on the web showing attributes being applied to the service method, such as [WebGet]. The method requires no attributes at all. For maxStringContentLength to take affect, you need to correctly setup the binding and behavior. Here is the correct entries in the web.config file:

    <system.serviceModel>
      <behaviors>
        <endpointBehaviors>
          <behavior name="jsonBehavior">
            <enableWebScript />
          </behavior>
        </endpointBehaviors>
        <serviceBehaviors>
          <behavior name="DevServiceBehavior" >
            <serviceMetadata httpGetEnabled="true" />
          </behavior>
        </serviceBehaviors>
      </behaviors>
      <services>
        <service name="DeveloperService" behaviorConfiguration="DevServiceBehavior" >
          <endpoint address="" binding="webHttpBinding" contract="DeveloperService" bindingConfiguration="webHttpBindingDev" behaviorConfiguration="jsonBehavior">
            <identity>
              <dns value="localhost"/>
            </identity>
          </endpoint>
          <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
        </service>
      </services>
      <bindings>
        <webHttpBinding>
          <binding name="webHttpBindingDev">
            <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"  maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          </binding>
        </webHttpBinding>
      </bindings> 
      <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
    </system.serviceModel>
    
    0 讨论(0)
提交回复
热议问题