Upload
doreen-porter
View
244
Download
8
Tags:
Embed Size (px)
Citation preview
DCOM TechnologyDCOM Technology
What What is DCOM?is DCOM?
DCOM is just COMDCOM is just COM with a longer wirewith a longer wireDCOM extends COM to support DCOM extends COM to support
communication among objects on different communication among objects on different computerscomputers
CComponent omponent OObject bject MModelodel
COM is a platform-independent, COM is a platform-independent, distributed, object-oriented system for distributed, object-oriented system for creating binary software components that creating binary software components that can interact.can interact.
COM objects can be created with a variety COM objects can be created with a variety of programming languages. Object-of programming languages. Object-oriented languages, such as C++, provide oriented languages, such as C++, provide programming mechanisms that simplify programming mechanisms that simplify the implementation of COM objects. the implementation of COM objects.
Understanding COMUnderstanding COM
not an object-oriented language but a not an object-oriented language but a binary standardbinary standard
COM specifies an object model and COM specifies an object model and programming requirements that enable programming requirements that enable COM objects (also called COM COM objects (also called COM components) to interact with other objectscomponents) to interact with other objects
COM Design PrinciplesCOM Design Principles
Binary componentsBinary componentsAny programming languageAny programming languageAny location(in-process, cross-process, cross-Any location(in-process, cross-process, cross-
machine)machine)Zero sacrifice in-proc performanceZero sacrifice in-proc performanceSimplest model possibleSimplest model possible
Enable extensibility and adaptabilityEnable extensibility and adaptability
EncapsulationEncapsulationBlack box - no leakage of implementation Black box - no leakage of implementation
detailsdetailsAll object manipulation through strict All object manipulation through strict
interfacesinterfacesPolymorphismPolymorphism
via multiple via multiple interfacesinterfaces per class per class ““Discoverable”: QueryInterfaceDiscoverable”: QueryInterface
COM Design Principles..COM Design Principles..
COMObject
IUnknown
IRobot
IDispatch
InterfacesInterfaces
IUnknownIUnknown AddRefAddRef ReleaseRelease QueryInterfaceQueryInterface
IDispatchIDispatch GetIDsOfNamesGetIDsOfNames GetTypeInfoGetTypeInfo GetTypeInfoCountGetTypeInfoCount InvokeInvoke
Custom InterfacesCustom Interfaces
COM ArchitectureCOM Architecture
Communication details handled by the COM run-time
DCOM ArchitectureDCOM Architecture
Proxy & StubProxy & Stub
DCOM Wire ProtocolDCOM Wire Protocol
COMCOMClientClient
Component
CO
M R
unti
me
Server MachineClient Machine
TCP, UDP
SPX,IPX
Net BUI
HTTPCO
M R
unti
me
Proxy
Other Component
DCOM SecurityDCOM Security
Secure - Security is designed and built in. Not an Secure - Security is designed and built in. Not an option.option.
DCOM uses the extensible security framework DCOM uses the extensible security framework provided by Windows NT. provided by Windows NT.
Security configurableSecurity configurable DCOM stores Access Control Lists for componentsDCOM stores Access Control Lists for components ACLsACLs cancan be configured using the DCOM be configured using the DCOM
configuration tool (DCOMCNFG) or programmatically configuration tool (DCOMCNFG) or programmatically using the Windows NT registry and Win32 security using the Windows NT registry and Win32 security functions. functions.
COM Security ArchitectureCOM Security Architecture
COMCOMClientClient
Component
CO
M R
unti
me
Server MachineClient Machine
DCE
NT Kerberos
SSL, Certs.
NTLM
CO
M R
unti
me
Proxy
Other Component
Components & ReuseComponents & Reuse
Use existing tools and componentsUse existing tools and componentsReduce development time and costReduce development time and costCOM components easily configured as COM components easily configured as
DCOM componentsDCOM componentsCOM can use many other componentsCOM can use many other componentsCOM components are usable by many COM components are usable by many
technologiestechnologies
Location TransparencyLocation Transparency
COM Object locations are stored in COM Object locations are stored in registryregistry
Applications make calls using the globally Applications make calls using the globally unique CLSID.unique CLSID.
Path to COM server, or remote computer Path to COM server, or remote computer to run DCOM server is not needed by the to run DCOM server is not needed by the application.application.
Language NeutralityLanguage Neutrality
Various languages can be used to Various languages can be used to create components.create components.VB, Delphi for rapid developmentVB, Delphi for rapid developmentVC++, Java for advanced developmentVC++, Java for advanced developmentMicro Focus COBOLMicro Focus COBOL
Even more languages can be used to Even more languages can be used to use COM componentsuse COM componentsAdditionally scripting languages like VB Additionally scripting languages like VB
Script, JScriptScript, JScript
Connection ManagementConnection Management
Low BandwidthLow Bandwidth Header is 28 bytes over DCE-RPCHeader is 28 bytes over DCE-RPC Keep-Alive Messages bundled for all connections Keep-Alive Messages bundled for all connections
between Machinesbetween Machines
COM employs an efficient pinging protocol COM employs an efficient pinging protocol to detect if clients are activeto detect if clients are active
COM uses reference counting mechanism COM uses reference counting mechanism to do garbage collectionto do garbage collection
Efficient and ScalableEfficient and Scalable
Multiplexing - Single Port per-protocol, per server Multiplexing - Single Port per-protocol, per server process, regardless of # of objectsprocess, regardless of # of objects
Scalable - Connection-Less Protocols like UDP PreferredScalable - Connection-Less Protocols like UDP Preferred Established Connection-Oriented (TCP) Sessions Established Connection-Oriented (TCP) Sessions
Reused by same clientReused by same client
ServerServerClientClient
ClientClient
Load BalancingLoad Balancing
DCOM does not transparently provide load DCOM does not transparently provide load balancingbalancing
Makes it easy to implement load balancingMakes it easy to implement load balancingStatic load balancingStatic load balancingDynamic load balancing by means of a Dynamic load balancing by means of a
dedicated referral componentdedicated referral component
Platform NeutralityPlatform Neutrality
DCOM run-time is available for various platformsDCOM run-time is available for various platforms Win32 platforms, Solaris, Win32 platforms, Solaris, DEC UNIX, HPUX, Linux, DEC UNIX, HPUX, Linux,
MVS, VMS, MacMVS, VMS, Mac Cross-Platform Interoperability StandardCross-Platform Interoperability Standard
Per-Platform binary standardPer-Platform binary standard Unlike java, DCOM can utilizeUnlike java, DCOM can utilize powerful platform- powerful platform-
specific services and optimizationsspecific services and optimizations Less abstraction layers prevents additional overheadsLess abstraction layers prevents additional overheads
Creating a simple COM serverCreating a simple COM server
ATL COM AppWizardATL COM AppWizard
New ATL ObjectNew ATL Object
ATL Object AttributesATL Object Attributes
Add New MethodAdd New Method
Interface Definition LanguageInterface Definition Language
......
[[
object,object,
uuid(79522A15-BA3D-46A5-92D6-DA4BE60646F4),uuid(79522A15-BA3D-46A5-92D6-DA4BE60646F4),
dual,dual,
helpstring("ISimple Interface"),helpstring("ISimple Interface"),
pointer_default(unique)pointer_default(unique)
]]
interface ISimple : IDispatchinterface ISimple : IDispatch
{{
[id(1), helpstring("method StringLen")] HRESULT StringLen([in] [id(1), helpstring("method StringLen")] HRESULT StringLen([in] BSTR str, [out,retval] BSTR str, [out,retval] long* long* length);length);
};};
......
Source & Header FileSource & Header File
Source:Source:STDMETHODIMP CSimple::StringLen(BSTR str, long* length)STDMETHODIMP CSimple::StringLen(BSTR str, long* length)
{{
*length = SysStringLen(str);*length = SysStringLen(str);
return S_OK;return S_OK;
}}
Header:Header:......
public:public:
STDMETHOD(StringLen)(/*[in]*/ BSTR str, /*[out,retval]*/ STDMETHOD(StringLen)(/*[in]*/ BSTR str, /*[out,retval]*/ long* length);long* length);
......
Creating a Simple COM ClientCreating a Simple COM Client#include <stdio.h>#include <stdio.h>#import "SimpleCom.exe"#import "SimpleCom.exe"
int main(int argc, char* argv[])int main(int argc, char* argv[]){{
SIMPLECOMLib::ISimplePtr pSimple;SIMPLECOMLib::ISimplePtr pSimple;long len;long len;CoInitialize(NULL);CoInitialize(NULL);pSimple.CreateInstance(__uuidof(SIMPLECOMLib::Simple));pSimple.CreateInstance(__uuidof(SIMPLECOMLib::Simple));len = pSimple->StringLen("sample");len = pSimple->StringLen("sample");printf("Length = %d\n", len);printf("Length = %d\n", len);CoUninitialize();CoUninitialize();return 0;return 0;
}}
Exception HandlingException Handling
trytry
{{
len = pSimple->StringLen("sample");len = pSimple->StringLen("sample");
}}
catch (_com_error &e)catch (_com_error &e)
{{
printf(“%s\n”, e.Description());printf(“%s\n”, e.Description());
}}
Registering COM ObjectsRegistering COM Objects
COM dllCOM dllTo register: regsvr32 mycom.dllTo register: regsvr32 mycom.dllTo un-register: regsvr32 –u mycom.dllTo un-register: regsvr32 –u mycom.dll
COM exeCOM exeTo register: mycom.exe /regserverTo register: mycom.exe /regserverTo un-register: mycom.exe /unregserverTo un-register: mycom.exe /unregserver
Configure as DCOMConfigure as DCOM
Protocols for DCOMProtocols for DCOM
ReferancesReferances
MSDN Library OnlineMSDN Library OnlineProfessional ATL COM programming , Professional ATL COM programming ,
Richard Grimes, Wrox PublishingRichard Grimes, Wrox Publishing