WCF:远程服务器返回意外响应:(413)请求实体太大

时间:2014-06-26 21:13:46

标签: c# asp.net-mvc wcf web-config c#-3.0

我的客户端web.config有:

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

        <bindings>
            <basicHttpBinding>                  

                <binding name="BasicHttpBinding_ISchedulingService" closeTimeout="01:10:00"
                  openTimeout="00:11:00" receiveTimeout="01:10:00" sendTimeout="01:10:00"
                  allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                 maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text">
                  <readerQuotas maxDepth="2000000" 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:1234/SchedulingService.svc"
              binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISchedulingService"
                behaviorConfiguration="dataConfiguration"             contract="SchedulingService.ISchedulingService" name="BasicHttpBinding_ISchedulingService" />
        </client>

HostApp web.config有:

 <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <httpRuntime maxRequestLength="2147483647"/>
  </system.web>

  <system.serviceModel>
    <behaviors>      
          <endpointBehaviors>
            <behavior name="dataConfiguration">
              <dataContractSerializer maxItemsInObjectGraph="2147483647" />
            </behavior>
          </endpointBehaviors>
      <serviceBehaviors>
        <behavior>       
          <!-- To avoid disclosing m7tadata 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>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

ServiceApp web.config有:

<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <httpRuntime maxRequestLength="2147483647" executionTimeout="14400"/>
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- increase the size of data that can be serialized -->
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
          <!-- 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>

现在, 在客户端的Controller方法中,我试图传递给服务
 * 3600字符串[]列表服务

 *而是由分隔符分隔的3600行细节的字符串(Excel解析表)

(PS:每行有12个字符串值(总行数= 3600))

但我一直在接受:

The remote server returned an unexpected response: (413) Request Entity Too Large.

即使是200行上传 请指导。感谢

2 个答案:

答案 0 :(得分:1)

您没有在服务的配置文件中明确定义任何绑定或端点,因此您将获得一个带有basicHttpBinding的默认端点,其默认值为绑定。尝试a)在服务配置中定义basicHttpBinding并将其分配给明确定义的端点,或者b)定义将用于使用该配置文件的所有服务的默认basicHttpBinding

选项a

<bindings>
  <basicHttpBinding>                  
    <binding name="BasicHttpBinding_ISchedulingService" closeTimeout="01:10:00"
             openTimeout="00:11:00" receiveTimeout="01:10:00" 
             sendTimeout="01:10:00" allowCookies="false" 
             bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
             maxBufferPoolSize="2147483647" maxBufferSize="2147483647" 
             maxReceivedMessageSize="2147483647" messageEncoding="Text">
      <readerQuotas maxDepth="2000000" 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>
<services>
  <service name="SchedulingService">
    <endpoint address=""
              binding="basicHttpBinding"
              bindingConfiguration="BasicHttpBinding_ISchedulingService"
              contract="SchedulingService.ISchedulingService" 
              name="BasicHttpBinding_ISchedulingService" />
  </service>
</services>

在上面的配置中,使用名称“BasicHttpBinding_ISchedulingService”定义basicHttpBinding,并通过bindingConfiguration元素的<endpoint>属性将此定义分配给服务端点。 / p>

选项b

与上面的选项a类似,但绑定配置部分省略了name属性,并且没有定义服务端点。定义的绑定配置将用于使用basicHttpBinding的所有服务,除非通过bindingConfiguration属性覆盖显式定义的端点。

<bindings>
  <basicHttpBinding>                  
    <binding closeTimeout="01:10:00" openTimeout="00:11:00"
      <!-- Remaining binding conifguration snipped for brevity -->
    </binding>
  </basicHttpBinding>
</bindings>

答案 1 :(得分:0)

即使是200个记录列表,它仍然会出现同样的错误......所以最后我决定立即拨打相同的内容。祝贺指导

   int chunkSize = 100;

   for (var i = 0; i < Details.Count; i += chunkSize)
                {
                    List<List<string>> DetailsChunk = schoolDetails.Skip(i).Take(chunkSize).ToList();
                    result = scheduleClient.AddDetails(DetailsChunk, savedFileName);
                }