3

I use a dynamicproxyfactory in order to call any webservice by a wsdl string path. Unfortunalty, when a webservice answers a lot of data, an exception is raised :

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 ---

Server stack trace: à System.ServiceModel.Channels.HttpInput.ThrowMaxReceivedMessageSizeExceeded() à System.ServiceModel.Channels.HttpInput.GetMessageBuffer() à System.ServiceModel.Channels.HttpInput.ReadBufferedMessage(Stream inputStream) à System.ServiceModel.Channels.HttpInput.ParseIncomingMessage(Exception& requestException) à System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout) à System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout) à 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 timeout) à System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) à System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]: à System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) à System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) à IWS_MG.ProceedOperation(String xmlIn) à WS_MGClient.ProceedOperation(String xmlIn)}

This exception means the maxsize is 65536, and the data size received is larger.

Anybody knows how change the maxsize ?

For information, this is my code :

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);
                    }
tshepang
  • 12,111
  • 21
  • 91
  • 136
BaptX
  • 561
  • 1
  • 7
  • 21
  • Maybe the solution is to create dynamicly WebReference and not ServiceReference but I didn't find any tutorial on the web – BaptX Jun 24 '11 at 12:59

1 Answers1

3

I'm not familiar with the DynamicProxy library but the binding object should have a MaxReceivedMessageSize property as in the basicHttpBinding. You need to set it to a value greater than 64K that is appropriate for your application. Also, make sure that the service is configured with the same value for the binding the client is calling on.

Sixto Saez
  • 12,610
  • 5
  • 43
  • 51
  • Check the code, I already did that : myReaderQuotas.MaxStringContentLength = int.MaxValue; – BaptX Jun 24 '11 at 12:39
  • 1
    Sorry, I got the property names confused, I updated the answer for the other thing you should also check :) – Sixto Saez Jun 24 '11 at 13:02
  • Yes, the two need to be in synch. – Peter K. Jun 24 '11 at 13:08
  • It's a problem with the client because if I register the webservice as webreference, it's work. But the soft would become useless because it shouldn't call any webservice anymore, only those will have the same interface / contract. – BaptX Jun 24 '11 at 13:10
  • WCF allows setting the MaxReceivedMessageSize property of a binding in code so there should be a place in the DynamicProxy API to set the value. It would be wherever the API allows access to the underlying WCF binding. – Sixto Saez Jun 24 '11 at 13:18
  • I tried to find a way, but I didn't found anything about this problem.... anybody ? – BaptX Jun 27 '11 at 08:39