3

我使用 dynamicproxyfactory 以通过 wsdl 字符串路径调用任何 Web 服务。不幸的是,当 web 服务回答大量数据时,会引发异常:

System.ServiceModel.CommunicationException: Le quota de taille maximale autorisée pour les messages entrants (65536) a été dépassé。Pour augmenter le quota, utilisez la propriété MaxReceivedMessageSize sur l'élément de la liaison appropriée。---> System.ServiceModel.QuotaExceededException: Le quota de taille maximale autorisée pour les messages entrants (65536) a été dépassé。Pour augmenter le quota, utilisez la propriété MaxReceivedMessageSize sur l'élément de la liaison appropriée。--- Fin de la trace de la Pile d'exception interne ---

服务器堆栈跟踪: à System.ServiceModel.Channels.HttpInput.ThrowMaxReceivedMessageSizeExceeded() à System.ServiceModel.Channels.HttpInput.GetMessageBuffer() à System.ServiceModel.Channels.HttpInput.ReadBufferedMessage(Stream inputStream) à System.ServiceModel.Channels.HttpInput .ParseIncomingMessage(异常和 requestException)à System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan 超时)à System.ServiceModel.Channels.RequestChannel.Request(消息消息,TimeSpan 超时)à System.ServiceModel.Dispatcher.RequestChannelBinder。 Request(Message message, TimeSpan timeout) à System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs,TimeSpan 超时)à System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)à System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

[0] 处重新抛出异常: à System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) à System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 类型)à IWS_MG.ProceedOperation(字符串 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);
                    }
4

1 回答 1

3

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

于 2011-06-24T12:36:54.887 回答