예제 #1
0
        /// <summary>
        /// Invokes the func on a WCF implementation of a specific IPrestoService (T)
        /// </summary>
        /// <typeparam name="T">The type to return</typeparam>
        /// <param name="func">The action to take against the service</param>
        /// <example>
        /// this.Applications = new ObservableCollection<Application>(PrestoWcf.Invoke(service => service.GetAllApplications()));
        /// </example>
        public TReturn Invoke <TReturn>(Func <TService, TReturn> func)
        {
            if (func == null)
            {
                throw new ArgumentNullException("func");
            }

            var netTcpBinding = new NetTcpBinding();

            netTcpBinding.MaxReceivedMessageSize = int.MaxValue;

            using (var channelFactory = new WcfChannelFactory <TService>(netTcpBinding))
            {
                // The call to CreateChannel() actually returns a proxy that can intercept calls to the
                // service. This is done so that the proxy can retry on communication failures.
                TService prestoService = channelFactory.CreateChannel(GetEndpointAddress());
                return(func(prestoService));
            }
        }
예제 #2
0
 public WcfClientProxy(WcfChannelFactory <T> channelFactory)
     : base(typeof(T))
 {
     this._channelFactory = channelFactory;
 }