将JSON发送到C#WCF服务会导致:请求实体太大

时间:2018-06-25 09:38:15

标签: c# json web-services wcf

我一直在环顾四周,并检查了几个答案,但仍然遇到相同的问题。

我有一个WCF服务,该服务以JSON形式接收数据,然后对其进行处理。 我有一个调用此服务的控制台应用程序。 但是我仍然遇到相同的问题:“远程服务器返回了意外响应:(413)请求实体太大。

在我的控制台应用程序配置中,我有:

 <system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_IPaymentBehaviorService"  allowCookies="true"
               maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647">
              <readerQuotas maxDepth="32" maxArrayLength="2147483647" maxStringContentLength="2147483647"/>
            </binding>
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://localhost:50068/PaymentBehaviorService.svc"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IPaymentBehaviorService"
            contract="PaymentBehaviorServiceService.IPaymentBehaviorService"
            name="BasicHttpBinding_IPaymentBehaviorService" />
    </client>
</system.serviceModel>

我的服务器配置:

 <system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior>
      <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="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>
<protocolMapping>
  <add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />

正在发送的数据中的一行看起来像:

{ \"ReqId\":\"79\",\"TaxNbr\":\"889638963\",\"Amount\":\"29,4\",\"Invoice\":\"10/2330\",\"InvDate\":\"19/04/2018 0:00:00\",\"ExpDate\":\"19/04/2018 0:00:00\" }       

我只能在一个请求中发送大约450行。 我需要将行数提高到1500甚至更多。 我该怎么办?

我发现了很多类似的问题,但没有一个给我解决方案。

1 个答案:

答案 0 :(得分:0)

您在basicHttpBinding中使用过TransferMode属性了吗?将模式设置为“流式”