Title: Microsoft COM and 'NET Framework
1Microsoft COM and .NET Framework
- Srini Ganapathy
- Developer Support Engineer
- Developer Support Distributed Services
- Microsoft Corporation
2Agenda
- 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
3Brief 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
6Contexts
- 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
7ContextUtil Class
- Methods exposed by the ContextUtil class are
- SetComplete
- SetAbort
- EnableCommit
- DisableCommit
- IsCallerInRole
- GetNamedProperty
8ContextUtil Class (2)
- Some useful static members of ContextUtil class
- ActivityId
- IsSecurityEnabled
- TransactionId
- DeactivateOnReturn
- MyTransactionVote
9ContextUtil 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
10ContextUtil Class Transaction Control (2)
- public void TestTransMethod2()
-
- try
- //Do Some Transaction work
- ContextUtil.SetComplete()
-
- catch (Exception ex)
-
- ContextUtil.SetAbort()
- //Handle the exception
-
-
11ContextUtil Class Transaction Control (3)
- AutoComplete()
- public void TestTransMethod2()
-
- //Do Some Transaction work
-
- AutoComplete attribute calls SetComplete/SetAbort
appropriately
12Security
- 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
13Security Component Level
- Component-level security enabled using the
ComponentAccessControl attribute - ComponentAccessControl
- Role-based security enabled by attribute
- SecurityRole(AllUserGroup",true)
14Security 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
15Security SecurityCallContext Class
- SecurityIdentity contains information regarding
an identity in a COM call chain - Other important methods IsSecurityEnabled,
IsCallerInRole, IsUserInRole, etc.
16Loosely-Coupled Events Programming
- Attributes come in handy!!
- EventClass attribute declares an EventClass
- FireInParallel, AllowInprocSubscribers, and
PublisherFilter properties can be specified in
EventClass attribute constructor
17Queued 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
18Object Pooling
- Any .NET ServicedComponent could be pooled
- Pooling is made available through the
ObjectPooling attribute - ObjectPooling(MinPoolSize2, MaxPoolSize5)
- public class SVCCompClass ServicedComponent
-
19Object 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
20Object 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
21Remoting 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
22Hosting 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.
23Hosting 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
24Hosting 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()
25Hosting 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
26COM Component as a Web Service
- New feature with COM 1.5
- An easy check box creates the VRoot
- This approach uses .NET remoting
27Remoting Using a Custom Host
- This needs a listener process to expose the
endpoints for the COM component
28Remoting 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()
-
29Using 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
30Deployment 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")
31Deployment 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
32Deployment 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
33Miscellanea
- 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
34Good 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