Component Services

30
Component Services Tom Perkins - CertSIG

description

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. - PowerPoint PPT Presentation

Transcript of Component Services

Page 1: Component Services

Component ServicesTom Perkins - CertSIG

Page 2: Component Services

Software Component (Definition)

• A software component is a system element that– Offers a predefined service– Is able to communicate with other

components

Does something

Other component

Able to communicate with other components

Page 3: Component Services

Criteria

• Multiple use• Non-context-specific• Composable with other components• Encapsulated (cannot be

investigated through its interfaces)• A unit of independent deployment

and versioning

Page 4: Component Services

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.

Page 5: Component Services

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

Page 6: Component Services

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

Page 7: Component Services

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

Page 8: Component Services

3-Tier Approach

Presentation

Business Logic

Data

Active Server Pages

COM Components

DBMS (SQL Server,etc)

Implementation ChoiceTier Name

Page 9: Component Services

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

Page 10: Component Services

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

Page 11: Component Services

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

Page 12: Component Services

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

Page 13: Component Services

Calling a .NET Component from COM/COM+

COM Client

Registry

.NET Component

COM+ recognizes only COM components

??

Assembly Registration Process

Page 14: Component Services

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

Page 15: Component Services

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

Page 16: Component Services

Inside the Component’s Registry Entry

InprocServer32 key

Assembly key

registry Entry

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

mscoree.dll

COM Client

CCW (proxy)

.Net Component

Page 17: Component Services

Invoking a .NET Component from COM

COM/COM+ Runtime Common Language Runtime

COM Client .NET Component

mscoree.dllRegistryGUID

CoCreateInstance()DLLGetClassObject(

)

CCW

COM Call .NET Call

Page 18: Component Services

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

Page 19: Component Services

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+?

Page 20: Component Services

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.

Page 21: Component Services

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() {…} } }

Page 22: Component Services

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

Page 23: Component Services

Declarative Programming Example

• All details for enabling transactions done behind the scenes

• Advantages:– Less code– Reliability – platform should be validated– Flexibility – administrators can

reconfigure without recompiling

[Transaction(TransactionOption.Required)]

public class MySampleSC : ServicedComponent

{ … } Component requires Transaction Support

Page 24: Component Services

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

Page 25: Component Services

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

Page 26: Component Services

Component Services Administration Tool

Page 27: Component Services

Component Activation – Similar Context

COM+ COM+ Application Process

Context X

En

terp

rise

Serv

ices

Component A Component B Compatible

Contexts?COM+

catalog

ObjB = new ComponentB()

CoCreateInstance()

GUID

Runtime Information

YRuntime Information

Page 28: Component Services

Component Activation – Different Contexts

COM+ COM+ Application Process

Context X

En

terp

rise

Serv

ices

Component A Component B Compatible

Contexts?COM+

catalog

ObjB = new ComponentB()

CoCreateInstance()

GUID

Runtime Information

NRuntime Information

Pro

xy

Interception

Context Y

Page 29: Component Services

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

Page 30: Component Services

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