WCF错误 - (413)请求实体太大

时间:2014-05-16 00:18:45

标签: web-services web http-status-code-413

我有2个WCF服务一起工作。一个是类库,另一个是webservice。

它的工作到现在为止。但是,如果我尝试发送大量数据,它会给我带来413错误......

An exception was thrown: The remote server returned an error: (413) Request Entity Too Large.

下面是web.config文件 -

对于类库 -

  

                                     

    <add key="SMTP" value ="dummy"/>
    <add key="BookingEmailFrom" value ="dummy"/>
    <add key="BookingEmailToWBD" value ="dummy"/>

  </appSettings>
  <connectionStrings/>
  <system.web>
    <compilation debug="true" targetFramework="4.0"/>
    <!--
        The <authentication> section enables configuration 
        of the security authentication mode used by 
        ASP.NET to identify an incoming user. 
    -->
    <authentication mode="Windows"/>
    <!--
        The <customErrors> section enables configuration 
        of what to do if/when an unhandled error occurs 
        during the execution of a request. Specifically, 
        it enables developers to configure html error pages 
        to be displayed in place of a error stack trace.

        <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
         <error statusCode="403" redirect="NoAccess.htm" />
         <error statusCode="404" redirect="FileNotFound.htm" />
        </customErrors>
    -->
    <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
  </system.web>
  <!-- 
      The system.webServer section is required for running ASP.NET AJAX under Internet
      Information Services 7.0.  It is not necessary for previous version of IIS.
  -->
  <system.serviceModel>
    <services>
      <service name="JSONWebService.Service1" behaviorConfiguration="JSONWebService.Service1Behavior">
        <endpoint address="../Service1.svc" binding="webHttpBinding" contract="JSONWebService.IService1"
     

behaviorConfiguration = “webBehaviour”/&GT;                                                                                                                                                                                                                                                                   

     

对于Web服务客户端 -

<?xml version="1.0"?>
<configuration>
  <!-- 
      Note: As an alternative to hand editing this file you can use the 
      web admin tool to configure settings for your application. Use
      the Website->Asp.Net Configuration option in Visual Studio.
      A full list of settings and comments can be found in 
      machine.config.comments usually located in 
      \Windows\Microsoft.Net\Framework\vx.x\Config 
  -->
  <configSections>

  </configSections>
  <appSettings>
    <add key="ConnectionString" value="Server=dummy;uid=sa;pwd=dummy;database=dummy"/>
                  

---------------------- - &gt;                                                                                                                                                                             部分启用配置               安全认证方式使用的               ASP.NET识别传入的用户。            - &GT;                       部分启用配置               如果/当发生未处理的错误时该怎么办               在执行请求期间。特别,               它使开发人员能够配置html错误页面               显示以代替错误堆栈跟踪。

        <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
         <error statusCode="403" redirect="NoAccess.htm" />
         <error statusCode="404" redirect="FileNotFound.htm" />
        </customErrors>
    -->
    <pages>
      <controls>
        <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral,
     

公钥= 31BF3856AD364E35" /&GT;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 

          <!-- 
              Upon deployment, the following identity element should be removed or replaced to reflect the 
              identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
              automatically.
          -->
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        <endpoint address="basic" binding="webHttpBinding" contract="JSONWebService.IService1"
     

behaviorConfiguration = “webBehaviour”/&GT;               

      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehavior" >
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before
     

部署 - &gt;                                                                                                                                                                                                                                                         

    </bindings>


  </system.serviceModel>



</configuration>

任何帮助都会非常感激。

由于

2 个答案:

答案 0 :(得分:4)

您遇到邮件大小的WCF默认限制。要提高限制,请在web.config文件(服务器端)中使用maxReceivedMessageSize属性。

<system.serviceModel>
  <bindings>
    <basicHttpBinding>
      <binding maxReceivedMessageSize="10000000">
    </basicHttpBinding>
  </bindings>
</system.serviceModel>

答案 1 :(得分:1)

这可能真的很晚了,但对于其他任何一个也被困住的人来说。

最初的问题是通过BilalAlam描述的(增加maxRecievedMessageSize)解决的,但问题是需要通过端点中的 bindingConfiguration name <绑定到端点的绑定/ em>在绑定中。

实施例

<bindings>
  <webHttpBinding>
    <binding maxReceivedMessageSize="2147483647" name="NAMETOTIEENDPOINT">
      <readerQuotas maxStringContentLength="2000000"/>
    </binding>
  </webHttpBinding>
</bindings>
<services>
  <service>
    <endpoint address="basic" bindingConfiguration="NAMETOTIEENDPOINT" binding="webHttpBinding" contract="JSONWebService.IService1"  />
  </service>
</services>