在C#中设置web.config后仍然得到(413)“Request Entity Too Large”

时间:2013-11-13 16:33:23

标签: c# web-services asp.net-mvc-4 maxreceivedmessagesize

我正在使用带C#的MVC4开发一个Web应用程序。

我需要通过AJAX发送PDF,所以我将它们转换为base64并将它们发送到C#中的函数。该函数将调用Web服务上的另一个函数。

问题是,Web服务函数没有得到base64字符串,因为它非常大,但不是TOO大,它大约111,000个字符,如70kb。我收到错误413

pdfCony是我的base64字符串

enter image description here

我已经在网络服务的web.config中设置了maxRecievedMesage:

 <bindings>
  <basicHttpBinding>
    <binding name="basicHttpsBinding" maxReceivedMessageSize="524288000" />
    <binding name="mexHttpBinding" maxReceivedMessageSize="524288000" />
  </basicHttpBinding>
</bindings>
<services>
  <service behaviorConfiguration="ServicioCCMasAvalBehavior" name="ServicioCCMasAval.ServicioCCMasAval">
    <endpoint address="/" binding="basicHttpBinding" contract="ServicioCCMasAval.IServicioCCMasAval" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>
</services>

所以我不知道是什么问题。请帮助。

3 个答案:

答案 0 :(得分:5)

非常感谢。但是我找到了另一个web.config示例中的解决方案

这是我的web.config:

<bindings>
  <basicHttpBinding>
    <binding name="basicHttpsBinding" maxReceivedMessageSize="524288000" />
    <binding name="mexHttpBinding" maxReceivedMessageSize="524288000" />
  </basicHttpBinding>
</bindings>
<services>
  <service behaviorConfiguration="ServicioCCMasAvalBehavior" name="ServicioCCMasAval.ServicioCCMasAval">
    <endpoint address="/" binding="basicHttpBinding" contract="ServicioCCMasAval.IServicioCCMasAval" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>
</services>

我错过了enpoint上的 bindingConfiguration 。现在这是我的工作webconfig:

<bindings>
  <basicHttpBinding>
    <binding name="basicHttpBinding" maxReceivedMessageSize="524288000" />
    <binding name="mexHttpBinding" maxReceivedMessageSize="524288000" />
  </basicHttpBinding>
</bindings>
<services>
  <service behaviorConfiguration="ServicioCCMasAvalBehavior" name="ServicioCCMasAval.ServicioCCMasAval">
    <endpoint address="/" binding="basicHttpBinding" bindingConfiguration="basicHttpBinding" contract="ServicioCCMasAval.IServicioCCMasAval" />      
  </service>
</services>

真的非常感谢。

答案 1 :(得分:1)

这是正确的配置,但我认为Visual Studio有自己的配置文件,因此当您处于调试模式时,您实际上必须将Visual Studio的app.config更改为与C:\ Program Files相同的路径( x86)\ Microsoft Visual Studio 10.0 \ Common7 \ IDE \ EXE我相信。还有maxSend不确定你是否翻转了

如果您正在远程调试,请忽略此答案

答案 2 :(得分:1)

我遇到了同样的问题,但对于我的情况,我必须传输非常大的文件(超过1Go),并且绑定配置必须在Streamming上,

以下是我解决问题的方法:

<bindings>
  <basicHttpBinding>
    <binding name="HttpStreaming" maxReceivedMessageSize="67108864" transferMode="Streamed"/>
  </basicHttpBinding>

  <!-- an example customBinding using Http and streaming-->
  <customBinding>
    <binding name="Soap12">
      <textMessageEncoding messageVersion="Soap12WSAddressing10" />
      <httpTransport transferMode="Streamed" maxReceivedMessageSize="67108864"/>
    </binding>
  </customBinding>
</bindings>

<services>
  <service name="FileTransferService">
    <endpoint address="http://localhost:40040/FileTransferService.svc" binding="basicHttpBinding" bindingConfiguration="HttpStreaming" name="NameSpace.FileTransferService" contract="NameSpace.IFileTransferService" />
  </service>
</services>