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);
}