【问题标题】:How do I configure MaxReceivedMessageSize in IIS hosted ASP.NET Web API (v1)?如何在 IIS 托管的 ASP.NET Web API (v1) 中配置 MaxReceivedMessageSize?
【发布时间】:2014-01-25 03:13:17
【问题描述】:

编辑: 我误诊了异常。它来自我的 Web API 控制器中的 WCF 客户端调用,而不是来自 Web API 客户端。通过在我的 WCF 客户端绑定配置中设置 maxReceivedMessageSize 可以轻松修复。

我超出了 Web API 中的最大消息大小。我可以找到如何在 WCF 和自托管的 Web API 中配置它,但我找不到在 IIS 托管的 Web API 中配置它的位置。

这是一个例外:

CommunicationException The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize prop
erty on the appropriate binding element. Void HandleReturnMessage(System.Runtime.Remoting.Messaging.IMessage, System.Runtime.Remoting.Messaging.IMessage)
Server stack trace:
   at System.ServiceModel.Channels.HttpInput.ThrowMaxReceivedMessageSizeExceeded()
   at System.ServiceModel.Channels.HttpInput.ReadBufferedMessage(Stream inputStream)
   at System.ServiceModel.Channels.HttpInput.ParseIncomingMessage(HttpRequestMessage httpRequestMessage, Exception& requestException)
   at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
   at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Channels.ClientReliableChannelBinder`1.RequestClientReliableChannelBinder`1.OnRequest(TRequestChannel channel, Message message, TimeSpan timeout, MaskingMode maskingMode)
   at System.ServiceModel.Channels.ClientReliableChannelBinder`1.Request(Message message, TimeSpan timeout, MaskingMode maskingMode)
   at System.ServiceModel.Security.SecuritySessionClientSettings`1.SecurityRequestSessionChannel.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

在哪里可以访问 Web API 绑定设置以便设置MaxReceivedMessageSize

【问题讨论】:

    标签: asp.net-web-api


    【解决方案1】:

    您的帖子令人困惑...您的异常与 WCF 自托管有关,但您的问题是关于 IIS 托管应用程序...它们都是不同的...无论如何这里是两个主机的选项:

    1. Selfhost:您可以在HttpSelfhostConfiguration 上找到MaxReceivedMessageSize 设置

    2. Webhost:在这种情况下,您需要进行一些设置。您可以在这里查看我的回复:https://stackoverflow.com/a/17324840/1184056

    【讨论】:

    • 实际上,WCF 客户端例外...我在第一次通过生产日志时误诊,但您在回答中的评论让我转向了正确的方向,所以我只是需要在客户端绑定配置中设置 maxReceivedMessageSize。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-18
    • 1970-01-01
    • 1970-01-01
    • 2014-05-11
    • 2020-03-09
    • 1970-01-01
    相关资源
    最近更新 更多