using System; using System.Linq; using System.ServiceModel; using System.Collections.Generic; using System.Xml; using System.ServiceModel.Description; namespace BatchService.Framework.Utility { /// /// Wcf°ïÖúÀà /// public class WcfServiceProxy { /// /// ¶¯Ì¬´´½¨Wcf¿Í»§¶Ë´úÀíʵÀý /// /// Contract/½Ó¿Ú /// Wcf·þÎñµØÖ· /// ´úÀíʵÀý public static T CreateServiceProxy(string uri) { var key = string.Format("{0} - {1}", typeof(T), uri); if (Caching.Get(key) == null) { var binding = new BasicHttpBinding(); binding.MaxReceivedMessageSize = maxReceivedMessageSize; binding.ReaderQuotas = new XmlDictionaryReaderQuotas(); binding.ReaderQuotas.MaxStringContentLength = maxReceivedMessageSize; binding.ReaderQuotas.MaxArrayLength = maxReceivedMessageSize; binding.ReaderQuotas.MaxBytesPerRead = maxReceivedMessageSize; binding.OpenTimeout = timeout; binding.ReceiveTimeout = timeout; binding.SendTimeout = timeout; var chan = new ChannelFactory(binding, new EndpointAddress(uri)); foreach (OperationDescription op in chan.Endpoint.Contract.Operations) { var dataContractBehavior = op.Behaviors.Find(); if (dataContractBehavior != null) dataContractBehavior.MaxItemsInObjectGraph = int.MaxValue; } chan.Open(); var service = chan.CreateChannel(); Caching.Set(key, service); return service; } else { return (T)Caching.Get(key); } } private const int maxReceivedMessageSize = 2147483647; private static TimeSpan timeout = TimeSpan.FromMinutes(10); } }