예제 #1
0
        public static int Main(String[] args)
        {
            int ret = 0;

            Console.WriteLine("CLR Remoting Sample: Custom Proxy");

            Type[] types = new Type[2];
            types[0] = typeof(IFaq);
            types[1] = typeof(IBaz);

            Console.WriteLine("Generate a new MyProxy using the Type");

            MyProxy myProxy = new MyProxy(typeof(MarshalByRefObject), types);

            Console.WriteLine("Obtain the transparent proxy from myProxy");
            MarshalByRefObject mbr = (MarshalByRefObject)myProxy.GetTransparentProxy();

            IFaq faq = (IFaq)mbr;
            int  r   = faq.MethodX(5, "hi");

            Console.WriteLine("{0}", r);

            IBaz baz = (IBaz)faq;
            int  r2  = baz.MethodY(123.45);

            Console.WriteLine("{0}", r);

            Console.WriteLine("Sample Done");
            return(ret);
        }
예제 #2
0
        public static int Main(String[] args)
        {
            int ret = 0;

            Console.WriteLine("CLR Remoting Sample: Custom Proxy");

            Console.WriteLine("Generate a new MyProxy using the Type");
            MyProxy myProxy = new MyProxy(typeof(Test));

            Console.WriteLine("Obtain the transparent proxy from myProxy");
            Test test = (Test)myProxy.GetTransparentProxy();

            Console.WriteLine("Calling the Proxy");
            int i2 = test.Method1("String1", 1.2, 6);

            Console.WriteLine("Checking result");
            if (5 == i2)
            {
                Console.WriteLine("Test.Method1 PASSED : returned {0}", i2);
                ret = 0;
            }
            else
            {
                Console.WriteLine("Test.Method1 FAILED : returned {0}", i2);
                ret = -1;
            }

            Console.WriteLine("Sample Done");
            return(ret);
        }
        public static int Main(String[] args)
        {
            ChannelServices.RegisterChannel(new HttpChannel(), false /*ensureSecurity*/);

            int ret = 0;

            Console.WriteLine("CLR Remoting Sample: Custom Proxy");

            Console.WriteLine("Generate a new MyProxy using the Type");
            Type    type    = typeof(HelloService);
            String  url     = "http://localhost/RemotingHello/HelloService.soap";
            MyProxy myProxy = new MyProxy(type, url);

            Console.WriteLine("Obtain the transparent proxy from myProxy");
            HelloService helloService = (HelloService)myProxy.GetTransparentProxy();

            Console.WriteLine("Calling the Proxy");
            try
            {
                String str = helloService.ReturnGreeting("bill");

                Console.WriteLine("Checking result : {0}", str);

                if (str == "Hi there bill, you are using .NET Remoting")
                {
                    Console.WriteLine("helloService.HelloMethod PASSED : returned {0}", str);
                    ret = 0;
                }
                else
                {
                    Console.WriteLine("helloService.HelloMethod FAILED : returned {0}", str);
                    ret = -1;
                }
            }

            catch (System.Net.WebException e)
            {
                Console.WriteLine("\nHandled Exception!!!\nPlease view the sample documentation in order to properly configure IIS to run this sample.\n");
                Console.WriteLine(e.Message);
            }
            catch (System.Runtime.Remoting.RemotingException e)
            {
                Console.WriteLine("\nHandled Exception!!!\nPlease view the sample documentation in order to properly configure IIS to run this sample.\n");
                Console.WriteLine(e.Message);
            }

            Console.WriteLine("Sample Done");
            return(ret);
        }