我使用dynamicproxyfactory来通过wsdl字符串路径调用任何web服务。不幸的是,当网络服务回答大量数据时,会引发异常:
System.ServiceModel.CommunicationException: Le quota de taillemaximaleautorisée pour les messages entrants(65536)a étédépassé。倒入增量配额, utilisezlapropriété MaxReceivedMessageSize sur l'élément de laliaisonappropriée。 ---> System.ServiceModel.QuotaExceededException: Le quota de taillemaximaleautorisée pour les messages entrants(65536)a étédépassé。倒入增量配额, utilisezlapropriété MaxReceivedMessageSize sur l'élément de laliaisonappropriée。 ---鳍 de la trace de la pile d'exception interne ---
服务器堆栈跟踪:à System.ServiceModel.Channels.HttpInput.ThrowMaxReceivedMessageSizeExceeded() 一个 System.ServiceModel.Channels.HttpInput.GetMessageBuffer() 一个 System.ServiceModel.Channels.HttpInput.ReadBufferedMessage(流 inputStream)à System.ServiceModel.Channels.HttpInput.ParseIncomingMessage(例外&安培; requestException)à System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(时间跨度 超时)à System.ServiceModel.Channels.RequestChannel.Request(消息 消息,TimeSpan超时)à System.ServiceModel.Dispatcher.RequestChannelBinder.Request(消息 消息,TimeSpan超时)à System.ServiceModel.Channels.ServiceChannel.Call(字符串 动作,布尔单向, ProxyOperationRuntime操作, Object [] ins,Object [] outs,TimeSpan 超时)à System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall,ProxyOperationRuntime 操作)à System.ServiceModel.Channels.ServiceChannelProxy.Invoke(即时聊天 消息)
在[0]处重新抛出异常:à System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(即时聊天 reqMsg,IMessage retMsg)à System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&安培; msgData,Int32类型)à IWS_MG.ProceedOperation(String xmlIn) àWS_MGClient.ProceedOperation(String xmlIn)}
此异常表示maxsize为65536,接收的数据大小更大。
有人知道如何更改maxsize吗?
有关信息,这是我的代码:
try
{
// Factory Creation with WCF WSDL address
DynamicProxyFactory factory = new DynamicProxyFactory(sServiceWsdl);
// Solution test which doesn't work
foreach (ServiceEndpoint endpoint in factory.Endpoints)
{
Binding binding = endpoint.Binding;
XmlDictionaryReaderQuotas myReaderQuotas = new XmlDictionaryReaderQuotas();
myReaderQuotas.MaxStringContentLength = int.MaxValue;
myReaderQuotas.MaxArrayLength = int.MaxValue;
myReaderQuotas.MaxBytesPerRead = int.MaxValue;
myReaderQuotas.MaxDepth = int.MaxValue;
myReaderQuotas.MaxNameTableCharCount = int.MaxValue;
binding.GetType().GetProperty("ReaderQuotas").SetValue(binding, myReaderQuotas, null);
}
// Proxy Creation with Contract's name
DynamicProxy proxy = factory.CreateProxy(sContract);
XElement XmlIN = XElement.Parse(sXmlIN);
// Method call with parameters
XElement XmlOUT = XElement.Parse((string)proxy.CallMethod(sMethod, XmlIN.ToString()));
sXmlOUT = XmlOUT.ToString(SaveOptions.None);
proxy.Close();
}
catch (Exception e)
{
sXmlOUT = new XElement("ALL_XML_OUT", new XElement("APP_TRX", sAppTrx), new XElement("WS_RC", 1), new XElement("ERROR_MESS", e.Message)).ToString(SaveOptions.None);
}
答案 0 :(得分:2)
我不熟悉DynamicProxy库,但绑定对象应该与basicHttpBinding中的MaxReceivedMessageSize property一样。您需要将其设置为适合您的应用程序的大于64K的值。此外,请确保为客户端调用的绑定配置了相同的服务。