0

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

直到现在它工作正常。但是,如果我尝试发送大量数据,则会引发 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"/>

对于 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"/>

---------------------- --> 部分启用 ASP.NET 用来识别传入用户的安全身份验证模式的配置。--> 部分可以配置如果/当在执行请求期间发生未处理的错误时要做什么。具体来说,它使开发人员能够配置要显示的 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,

PublicKeyToken=31BF3856AD364E35"/>

          <!-- 
              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"/>

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

部署 -->

    </bindings>


  </system.serviceModel>



</configuration>

任何帮助将非常感激。

谢谢

4

2 回答 2

5

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

<system.serviceModel>
  <bindings>
    <basicHttpBinding>
      <binding maxReceivedMessageSize="10000000">
    </basicHttpBinding>
  </bindings>
</system.serviceModel>
于 2014-05-16T02:05:06.027 回答
2

这可能真的很晚了,但对于其他也被卡住的人来说。

最初的问题由 BilalAlam 描述的内容(增加 maxRecievedMessageSize)解决,但您的问题是绑定需要通过端点中的bindingConfiguration和绑定中的名称绑定到端点。

例子

<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>
于 2017-09-21T14:57:31.390 回答