(413请求实体太大 [英] (413) Request Entity Too Large

查看:179
本文介绍了(413请求实体太大的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有WCF服务,当我想将参数作为大字符串(超过1mb)传递时,我有一个方法

I have WCF service, and I have a method when I want to pass parameter as big string (over 1mb)

我运行此wcf,并在WCF测试客户端中更改了配置,如下所示:

I run this wcf and in WCF Test Client I changed configuration as is shown below:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IMyService" sendTimeout="00:05:00"
                    maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
                    <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
                        maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
                </binding>
            </basicHttpBinding>
        </bindings>

当我尝试调用此方法时,我仍然有413个请求实体太大.

And when I try invoke this method I still have 413 request entity too large.

推荐答案

正如Matt Burland所建议的那样,您需要配置服务端以及客户端.有关详细信息,请参见使用配置文件配置服务 .该任务与您在网络客户端执行的操作没有太大不同.这是上述文章的摘录.

As Matt Burland suggested, you need to configure the service end as well as the client. See Configuring Services Using Configuration Files for details. The task is not much different from what you have done on the client end of the wire. Here's an excerpt from the aforementioned article.

WCF使用.NET的System.Configuration配置系统 框架.在Visual Studio中配置服务时,请使用 Web.config文件或App.config文件以指定设置.这 配置文件名称的选择由主机确定 您选择服务的环境.如果您使用IIS进行托管 您的服务,请使用Web.config文件.如果您使用任何其他 托管环境,请使用App.config文件.

WCF uses the System.Configuration configuration system of the .NET Framework. When configuring a service in Visual Studio, use either a Web.config file or an App.config file to specify the settings. The choice of the configuration file name is determined by the hosting environment you choose for the service. If you are using IIS to host your service, use a Web.config file. If you are using any other hosting environment, use an App.config file.

我建议不要将所有内容都设置为int.MaxValue,因为

I would suggest not setting everything to int.MaxValue as have a MaxReceivedMessageSize set to 2GB opens you up to DOS (Denial-Of-Service) attacks and the like. The remarks section of the MaxReceivedMessageSize property even states:

服务可以在线接收的消息大小 使用WSHttpBindingBase受内存量限制 为每条消息分配的.此消息大小限制旨在 限制遭受拒绝服务(DoS)攻击的可能性.

The size of the messages that can be received on the wire by services using the WSHttpBindingBase is bounded by the amount of memory allocated for each message. This bound on message size is intended to limit exposure to denial of service (DoS) attacks.

您现在可能只是想使其正常工作,但是建议不要以这种方式保留它.

You might just be trying to get it to work at this point, but it is far from recommended to leave it this way.

这篇关于(413请求实体太大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆