编辑: 我错误地诊断了异常。它来自我的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
?
答案 0 :(得分:2)
您的帖子令人困惑......您的例外与WCF自托管有关,但您的问题是关于IIS托管的应用程序......它们都不同......反正这里是两个主机的选项:
自托管:您可以在MaxReceivedMessageSize
HttpSelfhostConfiguration
设置
Webhost :在此情况下,您需要进行几项设置。您可以在此处查看我的回复:https://stackoverflow.com/a/17324840/1184056