Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
638 views
in Technique[技术] by (71.8m points)

c# - (413) Request Entity Too Large

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

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>

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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:

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...