【发布时间】:2011-06-24 10:50:55
【问题描述】:
我使用动态代理工厂来通过 wsdl 字符串路径调用任何 Web 服务。不幸的是,当 web 服务回答大量数据时,会引发异常:
System.ServiceModel.CommunicationException: Le quota de taille maximale autorisée 倒 les 消息参赛者 (65536) étédépassé。倒入增强剂 le 配额, 充分利用专有技术 MaxReceivedMessageSize sur l'élément de la liaison appropriée。 ---> System.ServiceModel.QuotaExceededException: Le quota de taille maximale autorisée 倒 les 消息参赛者 (65536) étédépassé。倒入增强剂 le 配额, 充分利用专有技术 MaxReceivedMessageSize sur l'élément de la liaison appropriée。 --- 鳍 de la trace de la pile d'exception 互联网---
服务器堆栈跟踪:à System.ServiceModel.Channels.HttpInput.ThrowMaxReceivedMessageSizeExceeded() 一种 System.ServiceModel.Channels.HttpInput.GetMessageBuffer() 一种 System.ServiceModel.Channels.HttpInput.ReadBufferedMessage(流 输入流)à 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[] 输入,Object[] 输出,TimeSpan 超时)à System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage 方法调用、代理操作运行时 操作)à System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage 留言)
在 [0] 处重新抛出异常:à System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) à System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(消息数据& msgData,Int32 类型)à IWS_MG.ProceedOperation(字符串 xmlIn) à WS_MGClient.ProceedOperation(字符串 xmlIn)}
这个异常表示maxsize为65536,接收到的数据量更大。
有人知道如何更改最大尺寸吗?
有关信息,这是我的代码:
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);
}
【问题讨论】:
-
也许解决方案是动态创建 WebReference 而不是 ServiceReference 但我在网上没有找到任何教程
标签: web-services wcf c#-4.0 reflection dynamic-proxy