IIS7.5 - (413)请求实体太大

时间:2016-10-08 18:55:11

标签: asp.net-mvc wcf iis-7.5

我见过所有类似的问题,但这对我没有帮助。

我有一个用作Windows服务的WCF应用程序。我还有一个asp.net mvc5站点,可以对抗IIS 7.5。

从标题中可以清楚地看到,当尝试上传摘要大小超过10Mb的文件时,我得到413响应。

我的WCF主机具有以下TCP绑定:

var tcpBinding = new NetTcpBinding
                {
                    ReliableSession = { InactivityTimeout = new TimeSpan(0, 12, 0, 0) },
                    MaxReceivedMessageSize = Int32.MaxValue,
                    MaxBufferPoolSize = Int32.MaxValue,
                    CloseTimeout = new TimeSpan(0, 5, 0),
                    ReceiveTimeout = new TimeSpan(0, 5, 0),
                    SendTimeout = new TimeSpan(0, 5, 0),
                    TransferMode = TransferMode.StreamedResponse,
                    ReaderQuotas = new XmlDictionaryReaderQuotas
                    {
                        MaxDepth = Int32.MaxValue,
                        MaxArrayLength = Int32.MaxValue,
                        MaxBytesPerRead = Int32.MaxValue,
                        MaxNameTableCharCount = Int32.MaxValue,
                        MaxStringContentLength = Int32.MaxValue
                    }
                };

我的WCF连接器(在网站中)具有以下绑定:

NetTcpBinding
            {
                MaxReceivedMessageSize = Int32.MaxValue,
                MaxBufferPoolSize = Int32.MaxValue,
                CloseTimeout = timeout5Min,
                ReceiveTimeout = timeout5Min,
                OpenTimeout = timeout5Min,
                SendTimeout = timeout5Min,
                TransferMode = TransferMode.Streamed,
                ReaderQuotas = new XmlDictionaryReaderQuotas
                {
                    MaxDepth = Int32.MaxValue,
                    MaxArrayLength = Int32.MaxValue,
                    MaxBytesPerRead = Int32.MaxValue,
                    MaxNameTableCharCount = Int32.MaxValue,
                    MaxStringContentLength = Int32.MaxValue
                }
            };

我在applicationHost.config文件的IIS配置中设置了它:

<location path="Site">
        <system.webServer>
            <serverRuntime uploadReadAheadSize="20971520" />
        </system.webServer>
    </location>

我在网站的Web.config文件中有以下设置:

<requestFiltering>
    <requestLimits maxAllowedContentLength="20971520" />
</requestFiltering>

但我仍然有413回复。 在本地,它可以与IIS Express一起使用。出于这个原因,我几乎可以肯定这笔交易是在IIS 7.5中,而不是在WCF主机的配置中。

请告诉我如何排除故障的想法:)。

UPD。 主持人代码:

string address = "net.tcp://localhost:8001/WcfService";
var wcfService = new WcfService();
ServiceHost _svcHost = new ServiceHost(wcfService, new Uri[] { });
var tcpBinding = (see above line "var tcpBinding = new NetTcpBinding...")
_svcHost.AddServiceEndpoint(typeof(IWcfService), tcpBinding, address);
_svcHost.Open();

客户代码:

IWcfService _service = ChannelFactory<IWcfService>.CreateChannel(GetNetTcpBinding(),
                    new EndpointAddress(String.Format("net.tcp://{0}:{1}/{2}", _hostAddress, _port, _serviceName)));
var co = (ICommunicationObject)_service;
co.Open();

0 个答案:

没有答案