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

  1. //==========================================================================
  2. //  File:       FooClient.cs
  3. //
  4. //  Summary:    This file demonstrates CallContext for NGWS Remoting
  5. //                       
  6. //
  7. //  Classes:    Client
  8. //
  9. //--------------------------------------------------------------------------
  10. //  This file is part of the Microsoft NGWS Samples.
  11. //
  12. //  Copyright (C) 2000 Microsoft Corporation.  All rights reserved.
  13. //==========================================================================
  14.  
  15. using System;
  16. using System.IO;
  17. using System.Reflection;
  18. using System.Runtime.Remoting;
  19. using FooAssembly;
  20.  
  21. public class Client
  22. {
  23.     public static int Main(string[] args)
  24.     {
  25.         Console.WriteLine("CallContext Remoting Sample\n");
  26.         int ret = Initialize(args);
  27.  
  28.         if (ret != -1)
  29.         {
  30.             switch (scenario)
  31.             {
  32.             case 1: 
  33.                 Scenario1();
  34.                 break;
  35.             }
  36.         }
  37.  
  38.         Console.WriteLine("\nEnd\n");
  39.  
  40.         return ret;
  41.     }
  42.  
  43.     public static void Scenario1()
  44.     {
  45.         SimpleObject so = new SimpleObject();
  46.  
  47.         CallContext.SetData("USER", "billg");
  48.  
  49.         String o = (String) CallContext.GetData("USER");
  50.  
  51.         Console.WriteLine("USER is '{0}'", o);
  52.  
  53.         String result;
  54.  
  55.         result = so.DoWork();
  56.         Console.WriteLine("The returned String is '{0}'", result);
  57.  
  58.         ValueObject v = new ValueObject();
  59.         result = so.DoValueWork(v);
  60.         Console.WriteLine("The returned String is '{0}'", result);
  61.     }
  62.  
  63.     //---------------------------------------------------
  64.     public static int scenario = 1;
  65.  
  66.     public static int Initialize(String[] args)
  67.     {
  68.         if (args.Length == 0)
  69.         {
  70.             RemotingServices.ConfigureRemoting("FooClient.cfg");
  71.             return 0;
  72.         }
  73.  
  74.         for (int i=0;i<args.Length;i++)
  75.         {
  76.             if (
  77.                String.Compare(args[i],"HELP", true) == 0 ||
  78.                String.Compare(args[i],"?", true) == 0 ||
  79.                String.Compare(args[i],"/h", true) == 0 ||
  80.                String.Compare(args[i],"-h", true) == 0 ||
  81.                String.Compare(args[i],"-?", true) == 0 ||
  82.                String.Compare(args[i],"/?", true) == 0
  83.                )
  84.             {
  85.                 Usage();
  86.                 return -1;
  87.             }
  88.  
  89.             if (args[i].CompareTo("-s1")==0)
  90.             {
  91.                 scenario = 1;
  92.             }
  93.  
  94.             if (args[i].CompareTo("-cfg")==0)
  95.             {
  96.                 RemotingServices.ConfigureRemoting(args[i+1]);
  97.             }
  98.         }
  99.  
  100.         return 0;
  101.     }
  102.  
  103.     public static void Usage()
  104.     {
  105.         Console.WriteLine("Usage: FooClient [-cfg Configfile.cfg]\n");
  106.         Console.WriteLine("Examples : FooClient");
  107.         Console.WriteLine("Examples : FooClient -s1   (Send and receive info in the CallContext)");
  108.         Console.WriteLine("Examples : FooClient -s1 -cfg MyStockApp.cfg");
  109.     }
  110. }
  111.  
  112.