home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 40 / IOPROG_40.ISO / SOFT / NETFrameworkSDK.exe / comsdk.cab / samples.exe / Remoting / MyCOM / MyCOMRate.cs < prev    next >
Encoding:
Text File  |  2000-06-23  |  5.4 KB  |  194 lines

  1. //==========================================================================
  2. //  File:       MyCOMRate.cs
  3. //
  4. //  Summary:    This file implements client side of NGWS Remoting. 
  5. //            It illustrates NGWS Remoting with classic COM
  6. //           
  7. //  Classes:    MyCOMRate
  8. //
  9. //--------------------------------------------------------------------------
  10. //  This file is part of the Microsoft NGWS Samples.
  11. //
  12. //  Copyright (C) 1999 Microsoft Corporation.  All rights reserved.
  13. //==========================================================================
  14.  
  15. using System;
  16. using System.Text;
  17. using System.Security.Policy;
  18. using System.Runtime.Remoting;
  19. using System.IO;
  20.  
  21. using RateSvr;
  22.  
  23. public class MyCOMRate
  24. {
  25.     public static int Scenario1()
  26.     {
  27.         Console.WriteLine("new RateLookup ****\n");
  28.         Object o1 = new RateLookup();
  29.  
  30.         return Scenario5(o1);
  31.     }
  32.  
  33.     public static int Scenario2()
  34.     {
  35.         Console.WriteLine("new RateLookup ****\n");
  36.         Object o1 = new RateLookup();
  37.  
  38.         return Scenario5(o1);
  39.     }
  40.  
  41.     public static int Scenario3()
  42.     {
  43.         // Connecting to remote COM Object
  44.  
  45.         Console.WriteLine("GetObject http 80 ****\n");
  46.         Object o1 = Activator.GetObject(typeof(RateLookup), "http://localhost:80/COMZone/RateSvr.soap");
  47.  
  48.         return Scenario5(o1);
  49.     }
  50.  
  51.  
  52.     public static int Scenario4()
  53.     {
  54.         // Connecting to remote COM Object
  55.  
  56.         Console.WriteLine("GetObject http 7076 retsv1 ****\n");
  57.         Object o1 = Activator.GetObject(typeof(RateLookup), "http://localhost:7076/COMZone/RateSvr.soap");
  58.  
  59.         return Scenario5(o1);
  60.     }
  61.  
  62.     public static int Scenario5(Object obj)
  63.     {
  64.         double loanAmount = 0;
  65.         short loanTerm = 0;
  66.         double loanMinRate = 0;
  67.         loanAmount = 100;
  68.         loanTerm = 10;
  69.  
  70.         // Connecting to remote COM Object
  71.         Object o1 = obj;
  72.  
  73.         RateSvr._RateLookup _rateLookup = null;
  74.         _rateLookup = (_RateLookup)o1;
  75.  
  76.         for (int i=0;i<10;i++)
  77.         {
  78.             Console.WriteLine("Remote COM Object is " + ((o1 != null) ? o1.ToString() : "null"));
  79.         }    
  80.         Console.WriteLine("Making GetLoanRate call on COM interface");
  81.  
  82.         loanMinRate = _rateLookup.GetLoanRate(loanAmount,loanTerm);
  83.  
  84.         Console.WriteLine("PASSED: GetLoanRate method call on COM interface:" + loanMinRate);
  85.  
  86.         for (int i=1;i < 100; i++)
  87.         {
  88.             loanTerm = (short)i;
  89.             loanMinRate = _rateLookup.GetLoanRate(loanAmount,loanTerm);
  90.             Console.WriteLine("PASSED: GetLoanRate method call on COM interface:" + loanMinRate);
  91.         }
  92.  
  93.         return 0;
  94.     }
  95.  
  96.     public static int Main(string[] args)
  97.     {
  98.         Console.WriteLine("Remoting and classic COM Sample\n");
  99.         int ret = Initialize(args);
  100.  
  101.         if (ret != -1)
  102.         {
  103.             switch (scenario)
  104.             {
  105.             case 1: 
  106.                 Scenario1();
  107.                 break;
  108.             case 2: 
  109.                 Scenario2();
  110.                 break;
  111.             case 3: 
  112.                 Scenario3();
  113.                 break;
  114.             case 4: 
  115.                 Scenario4();
  116.                 break;
  117.             }
  118.         }
  119.  
  120.         Console.WriteLine("\nEnd\n");
  121.  
  122.         return ret;
  123.     }
  124.  
  125.  
  126.     //---------------------------------------------------
  127.     public static int scenario = 1;
  128.  
  129.     public static int Initialize(String[] args)
  130.     {
  131.         if (args.Length == 0)
  132.         {
  133.             RemotingServices.ConfigureRemoting("MyCOM.cfg");
  134.             return 0;
  135.         }
  136.  
  137.         for (int i=0;i<args.Length;i++)
  138.         {
  139.             if (
  140.                String.Compare(args[i],"HELP", true) == 0 ||
  141.                String.Compare(args[i],"?", true) == 0 ||
  142.                String.Compare(args[i],"/h", true) == 0 ||
  143.                String.Compare(args[i],"-h", true) == 0 ||
  144.                String.Compare(args[i],"-?", true) == 0 ||
  145.                String.Compare(args[i],"/?", true) == 0
  146.                )
  147.             {
  148.                 Usage();
  149.                 return -1;
  150.             }
  151.  
  152.             if (args[i].CompareTo("-s1")==0)
  153.             {
  154.                 scenario = 1;
  155.             }
  156.  
  157.             if (args[i].CompareTo("-s2")==0)
  158.             {
  159.                 scenario = 2;
  160.             }
  161.  
  162.             if (args[i].CompareTo("-s3")==0)
  163.             {
  164.                 scenario = 3;
  165.             }
  166.  
  167.             if (args[i].CompareTo("-s4")==0)
  168.             {
  169.                 scenario = 4;
  170.             }
  171.  
  172.             if (args[i].CompareTo("-cfg")==0)
  173.             {
  174.                 RemotingServices.ConfigureRemoting(args[i+1]);
  175.             }
  176.         }
  177.  
  178.         return 0;
  179.     }
  180.  
  181.     public static void Usage()
  182.     {
  183.         Console.WriteLine("Usage: MyCOM [-s1/-s2/-s3/-s4] [-cfg Configfile.cfg]\n");
  184.         Console.WriteLine("Examples : MyCOM -s1 (Connecting directly to COM object - new localhost)");
  185.         Console.WriteLine("Examples : MyCOM -s2 (Connecting directly to COM object - new localhost)");
  186.         Console.WriteLine("Examples : MyCOM -s3 (Connecting directly to COM object - GetObject 80)");
  187.         Console.WriteLine("Examples : MyCOM -s4 (Connecting directly to COM object - GetObject 7076)");
  188.         Console.WriteLine("Examples : MyCOM -s1 -cfg MyCOM.cfg");
  189.         Console.WriteLine("Examples : MyCOM -s2 -cfg MyCOM.cfg");
  190.     }
  191. }
  192.  
  193.  
  194.