【问题标题】:DynamicProxyFactory error with received data size收到数据大小的 DynamicProxyFactory 错误
【发布时间】: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


【解决方案1】:

我不熟悉 DynamicProxy 库,但绑定对象应该有一个MaxReceivedMessageSize property,就像在 basicHttpBinding 中一样。您需要将其设置为适合您的应用程序的大于 64K 的值。此外,请确保 service 为客户端调用的绑定配置了相同的值。

【讨论】:

  • 检查代码,我已经这样做了:myReaderQuotas.MaxStringContentLength = int.MaxValue;
  • 对不起,我把属性名弄糊涂了,我更新了你还应该检查的另一件事的答案:)
  • 是的,两者需要同步。
  • 这是客户端的问题,因为如果我将 web 服务注册为 webreference,它就可以工作。但是该软件将变得无用,因为它不应该再调用任何网络服务,只有那些将具有相同的接口/合同。
  • WCF 允许在代码中设置绑定的 MaxReceivedMessageSize 属性,因此 DynamicProxy API 中应该有一个位置来设置该值。它将位于 API 允许访问底层 WCF 绑定的任何位置。
猜你喜欢
  • 2017-10-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-22
  • 2017-02-01
相关资源
最近更新 更多