WCF阅读器配额最大字符串内容长度配额(8192)

时间:2013-01-07 03:48:10

标签: c# asp.net wcf web-services endpoint

我之前在这里写了一个类似问题的问题,但我已经对正确的方法进行了更多的测试和研究,正确地进行了绑定和行为,虽然我现在有了更好的理解,但我仍然得到了这个问题。错误。我甚至已经通过客户端并以程序方式创建了绑定,因此我可以确定它使用了正确的设置。

客户端计划:

 public static UserAnalyticsFarEnd.UserAnalyticsMasterServiceClient MakeClient(string endpointUri)
    {
        UserAnalyticsFarEnd.UserAnalyticsMasterServiceClient client = null;

        // replicate all the binding info from app.config
        BasicHttpBinding binding = new BasicHttpBinding();
        binding.Name = "MaxSizeBasicBinding";
        // The interval of time for a connection to open, before the transport raises an exception.
        binding.OpenTimeout = TimeSpan.FromMinutes(1);
        // The interval of time that a connection can remain active, during which no application
        // messages are received, before it is dropped. This one is NOT important.
        binding.ReceiveTimeout = TimeSpan.FromMinutes(10);
        // The interval of time for an operation to complete before the transport raises an exception.
        // This one is important. The time here was increased so that a command to the Negotiator
        // has more than the default of one minute before it times out. Given that the Negotiator
        // tries 3 times on any database command, a total of 3 minutes, CBH changed this to 5 on 2/3/12.
        binding.SendTimeout = TimeSpan.FromMinutes(5);  // used to be 1
        binding.CloseTimeout = TimeSpan.FromMinutes(1);
        binding.AllowCookies = false;
        binding.BypassProxyOnLocal = false;
        binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
        binding.MessageEncoding = WSMessageEncoding.Text;
        binding.TextEncoding = System.Text.Encoding.UTF8;
        binding.TransferMode = TransferMode.Buffered;
        binding.UseDefaultWebProxy = true;
        //int maxMessageSize = 1024 * 1024; // reasonable size w/o allocating huge amt of memory
        // That 1MB was not big enough, so increase it to half the limit, 1,073,741,824
        int maxMessageSize = 1024 * 1024 * 1024;
        binding.MaxBufferSize = maxMessageSize;
        binding.MaxReceivedMessageSize = maxMessageSize;
        binding.ReaderQuotas.MaxBytesPerRead = maxMessageSize;
        binding.ReaderQuotas.MaxStringContentLength = maxMessageSize;
        binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
        binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
        binding.Security.Message.AlgorithmSuite = System.ServiceModel.Security.SecurityAlgorithmSuite.Default;
        binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
        binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;
        try
        {

            System.Net.AuthenticationManager.CredentialPolicy = null;
            EndpointAddress endpointAddress = new EndpointAddress(endpointUri);
            client = new UserAnalyticsFarEnd.UserAnalyticsMasterServiceClient(binding, endpointAddress);
            //client.ClientCredentials.Windows.AllowedImpersonationLevel =
            //    System.Security.Principal.TokenImpersonationLevel.Impersonation;
        }
        catch (Exception ex)
        {
            throw ex;
        }

        return client;

    }

服务端(Web.config)

<bindings>
  <basicHttpBinding>

    <binding name="BasicHttpBinding_Configuration" maxBufferSize="2147483647"
      maxReceivedMessageSize="2147483647">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
                 maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
      <security mode="TransportCredentialOnly">
        <transport clientCredentialType="None" proxyCredentialType="None"
            realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>

    <binding name="BasicBindingMaxLength" maxBufferSize="1073741824"
             maxReceivedMessageSize="1073741824">
      <readerQuotas maxDepth="1073741824" maxStringContentLength="1073741824"
                 maxArrayLength="1073741824" maxBytesPerRead="1073741824" maxNameTableCharCount="1073741824" />
      <security mode="TransportCredentialOnly">
        <!--<transport clientCredentialType="Windows" />-->
      </security>
    </binding>

  </basicHttpBinding>
</bindings>

   <service behaviorConfiguration="UserAnalyticsSvcBehaviors" name="CISE.ServiceEngine.MasterEngineProxy.Services.UserAnalyticsMasterService">

    <endpoint address="" binding="basicHttpBinding" behaviorConfiguration="Behaviors.EndpointBehavior" bindingConfiguration="BasicBindingMaxLength"
     contract="CISE.ServiceEngine.MasterEngineProxy.Interfaces.IUserAnalyticsMasterService">
    </endpoint>
    <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />

  </service>

 <behavior name="UserAnalyticsSvcBehaviors">
      <!-- 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>

如果有人可以在这里帮助我,我已经做了好几天了,似乎无法想出它默认设置的默认设置

1 个答案:

答案 0 :(得分:1)

将此配置放入服务配置

<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <httpRuntime executionTimeout="4800" maxRequestLength="2097150"/>
  </system.web>
  <system.serviceModel>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    <!--BINDDING-->
    <bindings>
      <basicHttpBinding>
      </basicHttpBinding>
      <customBinding>
        <binding name="LargeSilverlight" closeTimeout="00:21:00" openTimeout="00:20:00"
          receiveTimeout="00:20:00" sendTimeout="00:50:00">
          <textMessageEncoding maxReadPoolSize="2147483647" maxWritePoolSize="2147483647">
            <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
              maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          </textMessageEncoding>
          <httpTransport maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
            maxBufferSize="2147483647" />
        </binding>
      </customBinding>
    </bindings>
    <client>
    </client>
    <!--SERVICE-->
    <services>
      <service name="CISE.ServiceEngine.MasterEngineProxy.Services.UserAnalyticsMasterService"  behaviorConfiguration="SilverlightWCFLargeDataApplication" >
        <endpoint  address="" binding="customBinding" bindingConfiguration="LargeSilverlight" behaviorConfiguration="SilverlightWCFLargeDataApplication" contract="CISE.ServiceEngine.MasterEngineProxy.Interfaces.IUserAnalyticsMasterService" >
        </endpoint>

      </service>
    </services>

    <!--BEHAVIOR-->
    <behaviors>
      <serviceBehaviors>
        <behavior name="SilverlightWCFLargeDataApplication">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>

      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="SilverlightWCFLargeDataApplication">
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>
      </endpointBehaviors>
    </behaviors>


  </system.serviceModel>
  <system.webServer>

    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="500000000"></requestLimits>
      </requestFiltering>
    </security>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>