330 likes | 537 Views
Component Services. Tom Perkins - CertSIG. Software Component (Definition). A software component is a system element that Offers a predefined service Is able to communicate with other components. Other component. Does something. Able to communicate with other components. Criteria.
E N D
Component Services Tom Perkins - CertSIG
Software Component (Definition) • A software component is a system element that • Offers a predefined service • Is able to communicate with other components Other component Does something Able to communicate with other components
Criteria • Multiple use • Non-context-specific • Composable with other components • Encapsulated (cannot be investigated through its interfaces) • A unit of independent deployment and versioning
Components • Must be written to a specification (COM, Java Beans, etc) • Adherence to specification turns object into component • Makes object reusable • Components may be objects or collections of objects • Must adhere to Interface Description Language (IDL) • Accessing or sharing components across network links or processes • Serialization (marshalling) required to turn component or one of its interfaces into a bitstream.
Component Object Model (COM) • Platform for software components • Introduced by Microsoft in 1993 • Enables • Interprocess communication • Dynamic object creation • Umbrella term for several technologies • OLE • OLE Automation • ActiveX • COM+ • DCOM
COM • A way of using objects in different environments from the one they were created in • Across machine boundaries • Implementers must provide well-defined interfaces • Interfaces separate from implementation • You don’t need to know how object is implemented internally • Reuse through interfaces • Objects are responsible for their own creation and destruction through reference-counting • Replacements • COM .NET • Support for Web Services Windows Communication Foundation (WCF) • DCOM binary formats; WCF XML-based SOAP
Differences from Object-Oriented Programming • Object-Oriented Programming (OOP) • Software should model the real world objects it represents • Focuses on real-world interactions b/w objects • Attempts to create objects from nouns and verbs in a “use case” • Software Componentry • Programmers glue together prefabricated components • Like electronics or mechanics • Discourages anthropomorphism • Pessimistic about “end-user” programming
3-Tier Approach Tier Name Implementation Choice Presentation Active Server Pages Business Logic COM Components Data DBMS (SQL Server,etc)
COM+ 1.0 • Object Pooling • Objects kept in a pool until ready to be used • Just-In-Time Activation • Minimizes time an object lives and consumes resources • Client can hold reference a long time • But, server creates object only on 1st method call • Role-based Security • Access to parts of component are granted/denied based on role to which client belongs • Queued Components • Component execution in async or disconnected mode • Loosely-Coupled Events • An object publishes an event, other objects suscribe
COM+ 1.5 • COM+ components can be configured to run as a • Windows Service • Can start when Windows starts • Can run with system identity account – has high privileges • Web Service • Needs IIS on machine
COM+ 2.0 (.NET Framework) • Name: COM+2.0 .NET Framework • Major upgrade of COM • Replaces need for COM • Components execute in mangaged CLR • Provide memory management, security, and versioning to the component • COM+ 1.0 used for Windows 2000 • COM+ 1.5 used for XP and Windows Server 2003
Exposing .NET Components • COM+ recognizes only COM components • .NET component exposed to COM must be exposed as COM component • For a COM client to find a .NET Component: • .NET Component must be registered as a COM server in the Registry • AKA Assembly Registration Process
Calling a .NET Component from COM/COM+ COM Client Registry Assembly Registration Process ?? .NET Component COM+ recognizes only COM components
Assembly Registration Process • VS-Change Register For COM Interop option on Project|Property Pages|Configuration Properties (slightly different for VS2005) • -or- Assembly Registration tool (regasm.exe) • -or- Programmatically, use RegistrationServices class of System.Runtime.InteropServices namespace
But first … • Assembly must be signed • Assembly identity • Text Name • Version • Culture Information • Public key • Optional Digital Signature • Assign GUID for assembly itself, each class, each method Assembly
Inside the Component’s Registry Entry mscoree.dll registry Entry … InprocServer32 key … Assembly key … normally points to DLL used by COM to create component for managed code, contains path to mscoree.dll o knows how to launch a CLR process o and execute a managed DLL o uses Assembly key to find DLL - stores identity of DLL, not path - GAC searched, then others o mscoree creates instance of type o mscoree creates COM-Callable Wrapper (CCW) – proxy b/w COM client and managed code in DLL COM Client CCW (proxy) .Net Component
Invoking a .NET Component from COM COM/COM+ Runtime Common Language Runtime Registry .NET Component COM Client mscoree.dll GUID CoCreateInstance() DLLGetClassObject() COM Call .NET Call CCW
Exporting .Net Components as COM Type Libraries • CCW – late binding – type references resolved at runtime • Slow, no compile-time checking • Alternative – export .NET components as COM type libraries • Early binding – faster, compile-time type checking • Assembly Registration Process similar • Default extension .tlb
Architecture of Component Services • What are the basic components of COM+ architecture? • How is a COM+ application organized? • How does COM+ provide component services? • How does the .NET Framework interact with COM+?
Serviced Components • All .NET serviced components must derive from System.EnterpriseServices.ServicedComponent class. • Classes must be public and concrete • Classes must provide a public default constructor • COM cannot create an object and pass parameters for object creation at the same time.
A Basic Serviced Component Declaration • ServicedComponent class – has methods but no events or properties – Methods: • Activate() – startup method • CanBePooled() – can object be pooled? • Construct() – gives access to construction string, after constructor • Deactivate() – cleanup operations • DisposeObject() – finalize, removes COM+ reference using System.EnterpriseServices; namespace TEP { public class MySampleSC : ServicedComponent { public MySampleSC() {…} } }
Declarative Programming Model • Uses declarative tags to specify services component receives (transactions, JIT activation, object pooling) • Instructs COM+ to accomplish certain tasks • Visual C#, declarative tags specified by attributes • Attribute values can be modified at run time by reflection • Use Component Services administrative tool • Can change application’s behavior without compiling
Declarative Programming Example [Transaction(TransactionOption.Required)] public class MySampleSC : ServicedComponent { … } Component requires Transaction Support • All details for enabling transactions done behind the scenes • Advantages: • Less code • Reliability – platform should be validated • Flexibility – administrators can reconfigure without recompiling
COM+ Application • Definition: A group of serviced components that perform related functions. • Each component consists of interfaces and methods • Always stored in a DLL; 2 configurations Server Application Library Application • runs in its own process • COM+ provides surrogate process (dllhost.exe) • runs in process of client • loaded into process of client
COM+ Catalog • Stores information about COM+ applications • GUID identifies each COM+ application and serviced component • Also each’s runtime requirements • If requires Transaction, this is stored • Declarative attributes stored here • Physically split • COM+ Registration DB c:\windows\registration • Windows Registry within key HKEY_CLASSES_ROOT • Access and update through Component Services administrative tool – Control Panel
Component Activation – Similar Context COM+ Application Process COM+ Context X Compatible Contexts? Runtime Information COM+ catalog Y Enterprise Services Component A Component B Runtime Information CoCreateInstance() ObjB = new ComponentB() GUID
Component Activation – Different Contexts COM+ Application Process COM+ Context X Context Y Interception N Compatible Contexts? Runtime Information COM+ catalog Enterprise Services Component A Component B Proxy Runtime Information CoCreateInstance() ObjB = new ComponentB() GUID
Context • Definition: A set of runtime properties that define the execution environment for a serviced component • Created during activation process • Based on configuration of component • Objects with similar requirements share a context; incompatibledifferent contexts
Interception • A mechanism that allows COM+ to capture calls to any object and execute its own code before passing that call. • Example: only users authenticated with Supervisors security role are allowed to call ApproveOrder() method. • COM+ intercepts the call and accepts or rejects based on identity of user. • Objects in different contexts use a proxy rather than direct calls • Available at object level and method level