Microsoft COM and 'NET Framework - PowerPoint PPT Presentation

1 / 35
About This Presentation
Title:

Microsoft COM and 'NET Framework

Description:

Access, authentication, and impersonation levels specified using attributes at ... ImpersonationLevel=ImpersonationLevelOption.Impersonate) ... – PowerPoint PPT presentation

Number of Views:69
Avg rating:3.0/5.0
Slides: 36
Provided by: MicrosoftC
Category:

less

Transcript and Presenter's Notes

Title: Microsoft COM and 'NET Framework


1
Microsoft COM and .NET Framework
  • Srini Ganapathy
  • Developer Support Engineer
  • Developer Support Distributed Services
  • Microsoft Corporation

2
Agenda
  • Brief introduction to Microsoft COM
  • Microsoft .NET and CLR
  • COM services accessed through managed code
  • Contexts transactions
  • Security
  • Loosely-coupled events
  • Queued components
  • Object pooling just-in-time activation
  • Remoting and COM
  • Registration of COM components
  • Miscellanea
  • Questions

3
Brief Introduction to COM
  • COM is about providing services
  • Services provided by COM contexts
  • Automatic transactions
  • Object pooling
  • Just-in-time activation (JITA)
  • Loosely-coupled events
  • Etc.
  • COM provides these services at the operating
    system level

4
.NET CLR and COM
  • CLR introduces a newer and easier programming
    model for COM
  • The COM services are still available only at the
    operating system/unmanaged world
  • Transitions between managed/unmanaged layers are
    taken care of by System.EnterpriseServices
    namespace
  • Services are made available to components using
    attributes

5
.NET and ServicedComponent
  • COM class derives from ServicedComponent
  • Example
  • ComVisible(true)
  • ObjectPooling(MinPoolSize2, MaxPoolSize5)
  • Guid("57F01F20-9C0C-4e63-9588-720D5D537E66")
  • Transaction(TransactionOption.Required)
  • public class SVCCompClass ServicedComponent
  • In COM 1.0, the list of services are not changed
  • In COM 1.5 (Microsoft Windows XP Professional
    and .NET server), newer services are available to
    leverage CLR features

6
Contexts
  • Contexts are the primary service providers
  • System.EnterpriseServices.ContextUtil class
    provides access to contexts as did
    CoGetObjectContext
  • Rich set of static and member functions exposed
    by System.EnterpriseServices.ContextUtil

7
ContextUtil Class
  • Methods exposed by the ContextUtil class are
  • SetComplete
  • SetAbort
  • EnableCommit
  • DisableCommit
  • IsCallerInRole
  • GetNamedProperty

8
ContextUtil Class (2)
  • Some useful static members of ContextUtil class
  • ActivityId
  • IsSecurityEnabled
  • TransactionId
  • DeactivateOnReturn
  • MyTransactionVote

9
ContextUtil Class Transaction Control
  • public bool TestTransMethod()
  • //Setting the doneness bit to true
  • ContextUtil.DeactivateOnReturn true
  • //Setting the initial transaction voting to
    abort
  • ContextUtil.MyTransactionVote
    TransactionVote.Abort
  • //Do Some Transaction work
  • //if success, commit the work
  • ContextUtil.MyTransactionVote
    TransactionVote.Commit
  • return true

10
ContextUtil Class Transaction Control (2)
  • public void TestTransMethod2()
  • try
  • //Do Some Transaction work
  • ContextUtil.SetComplete()
  • catch (Exception ex)
  • ContextUtil.SetAbort()
  • //Handle the exception

11
ContextUtil Class Transaction Control (3)
  • AutoComplete()
  • public void TestTransMethod2()
  • //Do Some Transaction work
  • AutoComplete attribute calls SetComplete/SetAbort
    appropriately

12
Security
  • Access, authentication, and impersonation levels
    specified using attributes at the assembly level
  • assemblyApplicationAccessControl(
  • AccessChecksLevel
  • AccessChecksLevelOption.ApplicationComponent,
  • AuthenticationAuthenticationOption.Default,
  • ImpersonationLevelImpersonationLevelOption.Imper
    sonate)
  • These attributes act on the COM application as a
    whole

13
Security Component Level
  • Component-level security enabled using the
    ComponentAccessControl attribute
  • ComponentAccessControl
  • Role-based security enabled by attribute
  • SecurityRole(AllUserGroup",true)

14
Security SecurityCallContext class
  • Describes the chain of callers until the current
    method call
  • CurrentCall property returns SecurityCallContext
    for a component
  • SecurityCallers collection maintains the
    security call chain

15
Security SecurityCallContext Class
  • SecurityIdentity contains information regarding
    an identity in a COM call chain
  • Other important methods IsSecurityEnabled,
    IsCallerInRole, IsUserInRole, etc.

16
Loosely-Coupled Events Programming
  • Attributes come in handy!!
  • EventClass attribute declares an EventClass
  • FireInParallel, AllowInprocSubscribers, and
    PublisherFilter properties can be specified in
    EventClass attribute constructor

17
Queued Component Programming
  • Enabling an application to be queued
  • assembly ApplicationQueuing(Enabled
    true,QueueListenerEnabledtrue)
  • Enabling interface-level queuing applied on a
    component class
  • InterfaceQueuing(Interface IQueuedInterface"
  • Exception class specified through
    ExceptionClass attribute on a component class

18
Object Pooling
  • Any .NET ServicedComponent could be pooled
  • Pooling is made available through the
    ObjectPooling attribute
  • ObjectPooling(MinPoolSize2, MaxPoolSize5)
  • public class SVCCompClass ServicedComponent

19
Object Pooling (2)
  • The values should NOT be overridden using
    Component Services Explorer
  • Override CanBePooled method to return a vote on
    pooling
  • protected override bool CanBePooled()
  • return true

20
Object Pooling JITA
  • Both OP JITA could be combined for a simpler
    and a scalable component architecture
  • Enabling JITA on a pooled component returns it
    to the pool on each method return
  • From the client side, use Dispose() to return the
    object to the pool if JIT is not enabled

21
Remoting and COM
  • Remoting communication protocol between
    entities in CLR
  • Remoting could be used to access managed COM
    components
  • IIS as a remoting host
  • Custom host used to invoke COM component

22
Hosting a COM Component Using IISServer-Side
Configuration
  • Create a virtual directory out of the component
    directory. Assembly present in \bin subdirectory.
  • Expose end points and protocol using the
    Web.config file for the IIS VRoot.

23
Hosting a COM Component Using IIS Web.Config
File
  • ltconfigurationgt
  • ltsystem.runtime.remotinggt
  • ltapplicationgt
  • ltservicegt
  • ltwellknown mode"SingleCall"type"SVCCompSoap.SVC
    CompSoapCls,SVCCompSoap objectUri"SVCCompSoap.so
    ap"/gt
  • lt/servicegt
  • lt/applicationgt
  • lt/system.runtime.remotinggt
  • lt/configurationgt

24
Hosting a COM Component Using IISClient Side
  • Sample client code
  • RemotingConfiguration.Configure("SVCCompSoapClnt.c
    onfig")
  • SVCCompSoapCls obj new SVCCompSoap.SVCCompSoapCl
    s()
  • string str obj.Method1()
  • Console.WriteLine(str.ToString())
  • Console.ReadLine()
  • obj.Dispose()

25
Hosting a COM component using IIS Client
Configuration File
  • ltconfigurationgt
  • ltsystem.runtime.remotinggt
  • ltapplicationgt
  • ltclient url"http//localhost/SVCCompSoa
    p/"gt
  • ltwellknown
  • type"SVCCompSoap.SVCCompSoa
    pCls, SVCCompSoap"
  • url"http//localhost/SVCCom
    pSoap/SVCCompSoap.soap"/gt
  • lt/clientgt
  • lt/applicationgt
  • lt/system.runtime.remotinggt
  • lt/configurationgt

26
COM Component as a Web Service
  • New feature with COM 1.5
  • An easy check box creates the VRoot
  • This approach uses .NET remoting

27
Remoting Using a Custom Host
  • This needs a listener process to expose the
    endpoints for the COM component

28
Remoting Using a Custom Host Listener Process
  • The listener process can be configured to use a
    Config file containing protocol and port info
  • Code snippet of a listener process
  • static void Main(string args)
  • // TODO Add code to start application here
  • RemotingConfiguration.Configure("SVCCompTCPListen
    er.config")
  • Console.WriteLine("Listening on Port 8888")
  • Console.ReadLine()

29
Using a Custom Host Listener Processs Config
File
  • Config file for the listener process
  • ltconfigurationgt
  • ltsystem.runtime.remotinggt
  • ltapplication name"SVCCompTCP"gt
  • ltservicegt
  • ltwellknown mode"SingleCall"
    type"SVCCompTCP.SVCCompTCPCls, SVCCompTCP"
    objectUri"SVC.rem" /gt
  • lt/servicegt
  • ltchannelsgt
  • ltchannel ref"tcp" port8888" /gt
  • lt/channelsgt
  • lt/applicationgt
  • lt/system.runtime.remotinggt
  • lt/configurationgt

30
Deployment of COM Applications
  • Attributes to specify a library/server
    application
  • assemblyApplicationActivation(ActivationOption.S
    erver)
  • Provide a strong name to the assembly
  • assembly AssemblyKeyFile("..\\..\\SVCComp.snk")

31
Deployment of COM Applications (2)
  • Add the assembly to the global assembly cache
  • C\Documents and Settingsgt gacutil /I SVCComp.dll
  • Register the assembly with the COM
    infrastructure
  • C\Documents and Settingsgt regsvcs SVCComp.dll
  • Components could be registered only by members of
    the administrators group

32
Deployment of Client Proxies
  • Usual methodology of exporting works
  • Ensure compatibility is checked between COM
    versions (1.5 vs. 1.0)
  • After installation, set a reference in the client
    application

33
Miscellanea
  • Avoiding multiple installations of components in
    a COM package
  • Use a GUID to decorate a COM component class
  • OR
  • Explicitly set all parts of the AssemblyVersion
  • assembly AssemblyVersion("1.0.")
  • Static methods execute in callers context

34
Good Sources of Information
  • Platform SDK
  • COM Web Services
  • A good article on enterprise services and COM
  • A good article on COM 1.5

35
  • Thank you for joining us for Todays Microsoft
    Support WebCast
  • For information on all upcoming Support WebCasts
    and access to the archived content (streaming
    media, PowerPoint slides, and transcripts),
    please visit
  • http//support.microsoft.com/WebCasts
  • We sincerely appreciate your feedback. Please
    send any comments or suggestions regarding the
    Support WebCasts to feedback_at_microsoft.com.
    Include Support WebCasts in the subject line
Write a Comment
User Comments (0)
About PowerShow.com