Three methods of calling a function netTcpBinding

     Before it took a long time to study the WCF, and realized netTcpBinding Three methods of calling a function, maybe some people need it, so share it.

The main code is as follows.

        static  void the Main ( String [] args) 
        { 
            ICalculator2 menuProxy = CrateProxy <ICalculator2> ( " calculatorservice2 " ); // The method, the use of generic, convenient and practical, scalable, disadvantages, wood callback 
            var R & lt menuProxy = .Subtraction ( 120 , . 5 ); 
            Console.WriteLine ( " XY = {0} " , R & lt); 

            InstanceContext InstanceContext = new new InstanceContext ( new new CalculatorCallbackService ());
             the using (DuplexChannelFactory <the ICalculator> = ChannelFactory new newDuplexChannelFactory <the ICalculator> (InstanceContext, " CalculatorService " )) 
            { 
                the ICalculator Proxy = channelFactory.CreateChannel ();
                 the using (Proxy AS the IDisposable) 
                { 
                    proxy.Add ( . 1 , 2 ); // second method, the callback 
                    var Result = Proxy. Subtraction ( 100 , . 1 ); // three methods using the using, without the use of callback 
                    Console.WriteLine ( " XY = {0} "  , Result);
                    Console.Read ();
                }
            }
        }

Demo debugging method, start ServiceHosting, then start Client.

After commissioning shots are as follows:

Interested in this example, download the Demo

Reproduced in: https: //www.cnblogs.com/ushou/archive/2013/02/25/2931546.html

Guess you like

Origin blog.csdn.net/weixin_34253126/article/details/93162896