2014-01-24 110 views
1

編輯:我錯誤診斷了異常。它來自我的Web API控制器中的WCF客戶端調用,而不是來自Web API客戶端。通過在我的WCF客戶端綁定配置中設置maxReceivedMessageSize方便解決。如何在IIS託管的ASP.NET Web API(v1)中配置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) 

我在哪裏可以訪問網絡API綁定設置,所以我可以設置MaxReceivedMessageSize

回答

2

您的文章是混淆...您的例外是與WCF自主機,但你的問題是關於IIS託管的應用程序......他們倆是不同的......反正這裏有兩個主機的選項:

  1. Selfhost:你可以在HttpSelfhostConfiguration

  2. 網絡託管找到MaxReceivedMessageSize設置:您需要做幾項設置在這種情況下。你可以看看我的答覆這裏是:https://stackoverflow.com/a/17324840/1184056

+0

事實上,例外的是WCF客戶端...我誤診我的產品日誌的第一關,但在你的答案您的評論讓我轉向正確的方向,所以我只需要在客戶端綁定配置中設置maxReceivedMessageSize。 – MikeJansen