none
web引用WCF项目,请求的时候出现“请求因 HTTP 状态 413 失败: Request Entity Too Large。” RRS feed

  • 问题

  • RT,本人WEB项目是.NET2.0的网站,使用web引用引用了WCF项目,用于上传图片。然后程序一运行到与WCF通信的时候就报错了,错误:“请求因 HTTP 状态 413 失败: Request Entity Too Large。”。求.NET2.0下配置WCF客户端上传文件大小的方法!(注意:.NET2.0的,还有WCF服务端已经配置完毕)
    2015年7月10日 8:01

答案

  • 你好,

    针对这个错误信息,我建议你可以配置maxReceivedMessageSize。

    你可以参考下边的代码:

    在客户端配置文件中,主要是配置maxReceivedMessageSize

    <system.serviceModel>
        <bindings>
          <basicHttpBinding>
            <binding name="ServiceProxyBinding" closeTimeout="00:10:00" receiveTimeout="00:10:00"
              sendTimeout="00:10:00" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
              <readerQuotas maxStringContentLength="134217728" />
            </binding>
          </basicHttpBinding>
        </bindings>
        <client>
          <endpoint address="http://localhost:5239/AHMTService/PartService.svc"
            binding="basicHttpBinding" bindingConfiguration="ServiceProxyBinding"
            contract="UniCloud.ServiceContracts.IPartService" name="IPartService" />
        </client>
      </system.serviceModel>

    修改服务端web.config,主要也是配置maxReceivedMessageSize:

    <system.serviceModel>
        <services>
          <!--DecodeService 服务端配置 增加接收文件大小-->
          <service name="UniCloud.Services.DecodeService" behaviorConfiguration="MyServiceBehaviour" >
            <endpoint address="" binding="basicHttpBinding" bindingConfiguration="MyServiceBinding" contract="UniCloud.ServiceContracts.IDecodeService">
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
            <host>
              <baseAddresses>
                <add baseAddress="http://localhost:5239/AHMTService"/>
              </baseAddresses>
            </host>
          </service>
        </services>
        <bindings>
          <basicHttpBinding>
            <binding name="MyServiceBinding"  closeTimeout="00:10:00" receiveTimeout="00:20:00" sendTimeout="00:20:00"
    maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
              <security mode="None"></security>
            </binding>
          </basicHttpBinding>
        </bindings>
        <behaviors>
          <serviceBehaviors>
            <behavior name="MyServiceBehaviour">
              <!-- 为避免泄漏元数据信息,请在部署前将以下值设置为 false -->
              <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
              <!-- 要接收故障异常详细信息以进行调试,请将以下值设置为 true。在部署前设置为 false 以避免泄漏异常信息 -->
              <serviceDebug includeExceptionDetailInFaults="true" />
              <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <protocolMapping>
          <add binding="basicHttpsBinding" scheme="https" />
        </protocolMapping>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
      </system.serviceModel>

    更多详细信息,请看看这篇博客:http://www.cnblogs.com/Gyoung/p/3369316.html


    2015年7月15日 11:18
    版主