C# (400)即使配额已达到最大值,请求也不正确

C# (400)即使配额已达到最大值,请求也不正确,c#,wcf-binding,C#,Wcf Binding,我有一个c#winform应用程序 我正在调用服务器上的web服务 本质上,我上传的是一个字节数组 我知道配额,而且我(我想!)设置得很正确 我尝试过传递零字节,但调用通过了OK 在我的测试中,我试图上传719280字节 我收到400个错误请求 这是该服务的my web.config: <system.serviceModel> <behaviors> <serviceBehaviors> <behavior na

我有一个c#winform应用程序

我正在调用服务器上的web服务

本质上,我上传的是一个字节数组

我知道配额,而且我(我想!)设置得很正确

我尝试过传递零字节,但调用通过了OK

在我的测试中,我试图上传719280字节

我收到400个错误请求

这是该服务的my web.config:

  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ThrottledBehavior">
          <serviceTimeouts transactionTimeout="0.00:00:30" />
          <serviceThrottling maxConcurrentCalls="64" 
                             maxConcurrentSessions="50" 
                             maxConcurrentInstances="1" />
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service name="Sync" behaviorConfiguration="ThrottledBehavior">
        <endpoint address="Uploader.svc" 
                  binding="basicHttpBinding"
                  bindingConfiguration="basicHttpBindingEndPoint" 
                  contract="ISync" name="wsUploader"  />
      </service>
    </services>
    <bindings>
      <basicHttpBinding>
        <binding name="basicHttpBindingEndPoint" 
                 maxReceivedMessageSize="2147483647" 
                 messageEncoding="Mtom" 
                 closeTimeout="00:02:00" openTimeout="00:02:00" 
                 maxBufferPoolSize="2147483647" >
          <readerQuotas maxArrayLength="2147483647" 
                        maxBytesPerRead="2147483647" 
                        maxDepth="2147483647" 
                        maxStringContentLength="2147483647"
                        maxNameTableCharCount="2147483647"/>
        </binding>
      </basicHttpBinding>
    </bindings>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

增加中的“maxRequestLength”值

<httpRuntime
      executionTimeout="1200"
      maxRequestLength="1024000"
      appRequestQueueLimit="300" />

更新 转到绑定配置并将传输模式更改为流式传输

<bindings>
      <basicHttpBinding>
        <binding name="basicHttpBindingEndPoint" 
                 maxReceivedMessageSize="2147483647" 
                 transferMode="Streamed"

                 messageEncoding="Mtom" 
                 closeTimeout="00:02:00" openTimeout="00:02:00" 
                 maxBufferPoolSize="2147483647" >
          <readerQuotas maxArrayLength="2147483647" 
                        maxBytesPerRead="2147483647" 
                        maxDepth="2147483647" 
                        maxStringContentLength="2147483647"
                        maxNameTableCharCount="2147483647"/>
        </binding>
      </basicHttpBinding>
    </bindings>

试着打开跟踪(来源:),可能会透露一些细节。 将此添加到web.config:

<configuration>
   <system.diagnostics>
      <sources>
            <source name="System.ServiceModel" 
                    switchValue="Information, ActivityTracing"
                    propagateActivity="true">
            <listeners>
               <add name="traceListener" 
                   type="System.Diagnostics.XmlWriterTraceListener" 
                   initializeData= "c:\log\Traces.svclog" />
            </listeners>
         </source>
      </sources>
   </system.diagnostics>
</configuration>

我的特别问题是我使用了限制行为。此设置适用于小数据,但不适用于大数据。因此,将此绑定更改为正常/标准行为,如下所示:

    <behavior name="NormalBehaviour">
        <serviceMetadata httpGetEnabled="true" />
        <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>

而不是使用这个:

    <behavior name="ThrottledBehavior">
      <serviceTimeouts transactionTimeout="0.00:00:30" />
      <serviceThrottling maxConcurrentCalls="64" maxConcurrentSessions="50" maxConcurrentInstances="1" />
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>

为我工作

这里的实质是“serviceThrottling”已被删除。我本可以保持这种状态,但随后我必须增加maxConcurrentCalls、maxConcurrentSessions和maxConcurrentInstances,我确实尝试过这些,但它们的效果与限制行为相反,因此需要更长的时间来处理


感谢大家抽出时间参与本次活动

请参考@VigneshKumar Hi,感谢您的链接。虽然很有趣,但它并没有告诉我配置文件中的错误是什么?我只托管了1个服务,所以…?@AndrewSimpson-如果传入一个小字节数组(大于0但不是很大的数组),会发生什么情况?“这样行吗?”蒂姆谢谢你的建议。我刚刚试过(1字节),它工作正常。不过,尝试一下是件好事。谢谢你给我最新的答复,谢谢你抽出时间。我已经在我的web配置文件中设置了这个:嗨,是的,我刚刚做了:)。错误在于“ThrottledBehavior”的设置我的定义。特别是我对maxConcurrentInstances的价值。我跟踪的错误是已超过此设置。我正在创造一种新的行为,没有任何杂音,我将要测试:)所以,你实际上做的是从你的
-节点中剥离出一些
-节点?也许你应该在回答中指出这一点,为了让其他读者明白这一点,我的回答不是这样说的吗?它看起来像是某种默认的行为节点。如果你只是粗略的回答,你很可能会监督。但这只是一个建议;)随时接受建议。这个错误似乎有很多不同的解决方案,所以我希望它能帮助任何人。谢谢:)