Beispiel #1
0
		static void Main (string [] args)
		{
			DateTime start = DateTime.Now;
			HttpChannel chnl = new HttpChannel ();
#if NET_2_0
			ChannelServices.RegisterChannel (chnl, false);
#else
			ChannelServices.RegisterChannel (chnl);
#endif
			BaseRemoteObject obj = (BaseRemoteObject) Activator.GetObject (typeof (BaseRemoteObject),
				"http://localhost:1237/MyRemoteObject.soap");
			Test test = new Test ();
			test.t = "test";

			obj.test = test;
			SetValueDelegate svd = new SetValueDelegate (obj.setValue);
			IAsyncResult arValSet = svd.BeginInvoke (625, null, null);
			svd.EndInvoke (arValSet);

			GetValueDelegate gvd = new GetValueDelegate (obj.getValue);
			IAsyncResult arValGet = gvd.BeginInvoke (null, null);

			GetTextDelegate gtd = new GetTextDelegate (obj.getText);
			IAsyncResult arTxt = gtd.BeginInvoke (null, null);

			int iVal = gvd.EndInvoke (arValGet);
			string str = gtd.EndInvoke (arTxt);
			TimeSpan elapsed = DateTime.Now - start;

			Assert.AreEqual (625, iVal, "#A1");
			Assert.AreEqual ("Narendra", str, "#A2");

			Assert.IsTrue (elapsed.TotalMilliseconds > 9000, "#B1:" + elapsed.TotalMilliseconds);
			Assert.IsTrue (elapsed.TotalMilliseconds < 12000, "#B2:" + elapsed.TotalMilliseconds);
		}
Beispiel #2
0
        static void Main(string[] args)
        {
            DateTime start = System.DateTime.Now;

            HttpChannel channel = new HttpChannel();

            ChannelServices.RegisterChannel(channel);
            IMyRemoteObject obj = (IMyRemoteObject)Activator.GetObject(
                typeof(IMyRemoteObject),
                "http://localhost:1234/MyRemoteObject.soap");

            Console.WriteLine("Client.Main(): Reference to rem.obj. acquired");


            Console.WriteLine("Client.Main(): Will call setValue(42)");
            SetValueDelegate svDelegate = new SetValueDelegate(obj.SetValue);
            IAsyncResult     svAsyncres = svDelegate.BeginInvoke(42, null, null);

            Console.WriteLine("Client.Main(): Invocation done");

            Console.WriteLine("Client.Main(): Will call getName()");
            GetNameDelegate gnDelegate = new GetNameDelegate(obj.GetName);
            IAsyncResult    gnAsyncres = gnDelegate.BeginInvoke(null, null);

            Console.WriteLine("Client.Main(): Invocation done");

            Console.WriteLine("Client.Main(): EndInvoke for setValue()");
            svDelegate.EndInvoke(svAsyncres);
            Console.WriteLine("Client.Main(): EndInvoke for getName()");
            String name = gnDelegate.EndInvoke(gnAsyncres);

            Console.WriteLine("Client.Main(): received name {0}", name);

            Console.WriteLine("Client.Main(): Will now read value");
            int tmp = obj.GetValue();

            Console.WriteLine("Client.Main(): New server side value {0}", tmp);

            DateTime end      = System.DateTime.Now;
            TimeSpan duration = end.Subtract(start);

            Console.WriteLine("Client.Main(): Execution took {0} seconds.",
                              duration.Seconds);

            Console.ReadLine();
        }