(400)即使配额最大化也有不良请求

问题描述 投票:1回答:3

我有一个c#winform应用程序。

我在我的服务器上调用Web服务。

本质上我上传了一个字节数组。

我知道配额,我已经设置好了(我认为!)。

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

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

我收到400错误请求错误。

这是我的服务的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>
c# wcf-binding
3个回答
1
投票

增加“maxRequestLength”值

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

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

<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>

1
投票

尝试打开跟踪(来源:MSDN),也许这会揭示一些细节。将其添加到您的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>

1
投票

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

    <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,我尝试但是对于受限制的行为反作用,因此需要花费更长的时间来处理。

感谢大家为此付出时间

© www.soinside.com 2019 - 2024. All rights reserved.