home *** CD-ROM | disk | FTP | other *** search
- //==========================================================================
- // File: MyCOMRate.cs
- //
- // Summary: This file implements client side of NGWS Remoting.
- // It illustrates NGWS Remoting with classic COM
- //
- // Classes: MyCOMRate
- //
- //--------------------------------------------------------------------------
- // This file is part of the Microsoft NGWS Samples.
- //
- // Copyright (C) 1999 Microsoft Corporation. All rights reserved.
- //==========================================================================
-
- using System;
- using System.Text;
- using System.Security.Policy;
- using System.Runtime.Remoting;
- using System.IO;
-
- using RateSvr;
-
- public class MyCOMRate
- {
- public static int Scenario1()
- {
- Console.WriteLine("new RateLookup ****\n");
- Object o1 = new RateLookup();
-
- return Scenario5(o1);
- }
-
- public static int Scenario2()
- {
- Console.WriteLine("new RateLookup ****\n");
- Object o1 = new RateLookup();
-
- return Scenario5(o1);
- }
-
- public static int Scenario3()
- {
- // Connecting to remote COM Object
-
- Console.WriteLine("GetObject http 80 ****\n");
- Object o1 = Activator.GetObject(typeof(RateLookup), "http://localhost:80/COMZone/RateSvr.soap");
-
- return Scenario5(o1);
- }
-
-
- public static int Scenario4()
- {
- // Connecting to remote COM Object
-
- Console.WriteLine("GetObject http 7076 retsv1 ****\n");
- Object o1 = Activator.GetObject(typeof(RateLookup), "http://localhost:7076/COMZone/RateSvr.soap");
-
- return Scenario5(o1);
- }
-
- public static int Scenario5(Object obj)
- {
- double loanAmount = 0;
- short loanTerm = 0;
- double loanMinRate = 0;
- loanAmount = 100;
- loanTerm = 10;
-
- // Connecting to remote COM Object
- Object o1 = obj;
-
- RateSvr._RateLookup _rateLookup = null;
- _rateLookup = (_RateLookup)o1;
-
- for (int i=0;i<10;i++)
- {
- Console.WriteLine("Remote COM Object is " + ((o1 != null) ? o1.ToString() : "null"));
- }
- Console.WriteLine("Making GetLoanRate call on COM interface");
-
- loanMinRate = _rateLookup.GetLoanRate(loanAmount,loanTerm);
-
- Console.WriteLine("PASSED: GetLoanRate method call on COM interface:" + loanMinRate);
-
- for (int i=1;i < 100; i++)
- {
- loanTerm = (short)i;
- loanMinRate = _rateLookup.GetLoanRate(loanAmount,loanTerm);
- Console.WriteLine("PASSED: GetLoanRate method call on COM interface:" + loanMinRate);
- }
-
- return 0;
- }
-
- public static int Main(string[] args)
- {
- Console.WriteLine("Remoting and classic COM Sample\n");
- int ret = Initialize(args);
-
- if (ret != -1)
- {
- switch (scenario)
- {
- case 1:
- Scenario1();
- break;
- case 2:
- Scenario2();
- break;
- case 3:
- Scenario3();
- break;
- case 4:
- Scenario4();
- break;
- }
- }
-
- Console.WriteLine("\nEnd\n");
-
- return ret;
- }
-
-
- //---------------------------------------------------
- public static int scenario = 1;
-
- public static int Initialize(String[] args)
- {
- if (args.Length == 0)
- {
- RemotingServices.ConfigureRemoting("MyCOM.cfg");
- return 0;
- }
-
- for (int i=0;i<args.Length;i++)
- {
- if (
- String.Compare(args[i],"HELP", true) == 0 ||
- String.Compare(args[i],"?", true) == 0 ||
- String.Compare(args[i],"/h", true) == 0 ||
- String.Compare(args[i],"-h", true) == 0 ||
- String.Compare(args[i],"-?", true) == 0 ||
- String.Compare(args[i],"/?", true) == 0
- )
- {
- Usage();
- return -1;
- }
-
- if (args[i].CompareTo("-s1")==0)
- {
- scenario = 1;
- }
-
- if (args[i].CompareTo("-s2")==0)
- {
- scenario = 2;
- }
-
- if (args[i].CompareTo("-s3")==0)
- {
- scenario = 3;
- }
-
- if (args[i].CompareTo("-s4")==0)
- {
- scenario = 4;
- }
-
- if (args[i].CompareTo("-cfg")==0)
- {
- RemotingServices.ConfigureRemoting(args[i+1]);
- }
- }
-
- return 0;
- }
-
- public static void Usage()
- {
- Console.WriteLine("Usage: MyCOM [-s1/-s2/-s3/-s4] [-cfg Configfile.cfg]\n");
- Console.WriteLine("Examples : MyCOM -s1 (Connecting directly to COM object - new localhost)");
- Console.WriteLine("Examples : MyCOM -s2 (Connecting directly to COM object - new localhost)");
- Console.WriteLine("Examples : MyCOM -s3 (Connecting directly to COM object - GetObject 80)");
- Console.WriteLine("Examples : MyCOM -s4 (Connecting directly to COM object - GetObject 7076)");
- Console.WriteLine("Examples : MyCOM -s1 -cfg MyCOM.cfg");
- Console.WriteLine("Examples : MyCOM -s2 -cfg MyCOM.cfg");
- }
- }
-
-
-