home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2005 June (DVD) / DPPRO0605DVD.iso / dotNETSDK / SETUP.EXE / netfxsd1.cab / FL_QCObj_cs________.3643236F_FC70_11D3_A536_0090278A1BB8 < prev    next >
Encoding:
Text File  |  2001-08-21  |  4.1 KB  |  93 lines

  1. /*=====================================================================
  2.   File:      QCObj.cs
  3.  
  4.   Summary:   Demonstrates how Queued components is used in .NET
  5.  
  6. ---------------------------------------------------------------------
  7.   This file is part of the Microsoft .NET Framework SDK Code Samples.
  8.  
  9.   Copyright (C) Microsoft Corporation.  All rights reserved.
  10.  
  11. This source code is intended only as a supplement to Microsoft
  12. Development Tools and/or on-line documentation.  See these other
  13. materials for detailed information regarding Microsoft code samples.
  14.  
  15. THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  16. KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  17. IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  18. PARTICULAR PURPOSE.
  19. =====================================================================*/
  20.  
  21. using System;
  22. using System.Windows.Forms;
  23. using System.Reflection;
  24. using System.EnterpriseServices;
  25.  
  26.  
  27. // the ApplicationName attribute specifies the name of the
  28. // COM+ Application which will hold assembly components
  29. [assembly: ApplicationName("QCDemoSvr")]
  30.  
  31. // the ApplicationActivation.ActivationOption attribute specifies 
  32. // where assembly components are loaded on activation
  33. // Library : components run in the creator's process
  34. // Server : components run in a system process, dllhost.exe
  35. [assembly: ApplicationActivation(ActivationOption.Server)]
  36.  
  37. // AssemblyKeyFile specifies the name of the strong key
  38. // which will be used to sign the assembly
  39. // sn.exe -k was used to generate the keypair file
  40. #if BuildBat  // Used when building from the command line
  41.   [assembly: AssemblyKeyFile("QCDemoSvrCS.snk")]
  42. #else         // Used when building from within Visual Studio .NET
  43.   [assembly: AssemblyKeyFile("..\\..\\QCDemoSvrCS.snk")]
  44. #endif
  45.  
  46. // ApplicationQueuing enables queuing support for the COM+ component.
  47. // On building, a public queue will be created whose name
  48. // is the same as the COM+ application name specified above (qcdemosvr).
  49. // QueueListenerEnabled indicates whether the queued components listener
  50. // is enabled for the application. Since we specifiy true, the listener
  51. // will be launched on application startup and look for messages
  52. // in our public queue to be played back to the component
  53. [assembly: ApplicationQueuing(Enabled=true, QueueListenerEnabled=true)]
  54.  
  55. // IMPORTANT: for the sake of simplicity, this sample only requires an MSMQ
  56. // workgroup installation and is not set up to work with a domain controller.
  57. // In MSMQ workgroup mode, the active directory certificate store necessary to 
  58. // support message authentication is not available. So, we must disable call
  59. // authentication in our COM+ application in order to avoid an 'Access Denied' 
  60. // exception on creating the queued component. A real-world queued component 
  61. // requiring message authentication would not run in workgroup mode and would 
  62. // not set this attribute. See KnowledgeBase article Q247394 for more information. 
  63. [assembly: ApplicationAccessControl(Value=false, Authentication=AuthenticationOption.None)]
  64.  
  65.  
  66. namespace QCDemoServerCS
  67. {
  68.     // InterfaceQueuing enables queuing support for the IQComponent
  69.     // interface. Calls on the interface will be queued using MSMQ
  70.     [InterfaceQueuing]
  71.     public interface IQComponent 
  72.     {
  73.         void DisplayMessage(string msg);
  74.     }
  75.  
  76.  
  77.     // Our queued component class. Disconnected clients will use a 
  78.     // queue moniker to instantiate the class (see QCForm.cs). Method calls
  79.     // will packaged and placed in the queue. When the COM+ application
  80.     // holding this component is activated, manually or programmatically,
  81.     // the MSMQ listener will automatically retrieve any messages in our
  82.     // queue and pass them to the server code below. For this sample,
  83.     // the result is a series of message boxes corresponding to 
  84.     // individual object calls made from the client application.
  85.     public class QComponent  : ServicedComponent, IQComponent
  86.     {
  87.         public void DisplayMessage(string msg)
  88.         {
  89.             MessageBox.Show(msg, "Component Processing Message");
  90.         }
  91.     }
  92. }
  93.