DCOM(Distributed COM)

Download Report

Transcript DCOM(Distributed COM)

DCOM(Distributed COM)
Presenter:
資管研一 R89725009 呂江麟
資管研一 R89725037 劉英和
2015/7/17
1
大綱
Component Object Model
Distributed COM
DCOM Example With MFC
SAP:
DCOM Component Connector
2015/7/17
2
Component Object Model
COM – 軟體之間提供服務的一種標準方式
COM是一組規格:
描述COM元件建立時所必須遵守的準則
COM是一組服務:
COM函式庫提供支援此規格的服務或API
物件導向:識別碼、狀態、行為
位置通透性



2015/7/17
相同行程 (in-process server)
不同行程 (out-of-process server, local server)
不同機器 (remote server)
3
COM 的基本理念
組裝軟體 : Componentware
COM 的承諾



2015/7/17
以機器碼而非原始碼的重複使用方式
語言獨立性
位置通透性
4
COM介面
定義了其他軟體或元件可以使用的公用功能
一個COM介面必須滿足下列要求
 唯一的識別碼:IID(Interface ID)
 衍生自IUnknown介面
 一旦出版之後,便不允許更改
 介面並不是一個類別
 介面不是一個物件
2015/7/17
5
IUnknown介面
QueryInterface :
查詢物件是否有支援特定的介面
AddRef與Release
進行物件生命週期的管理,當參考計數
(Reference Count)的值為0時,物件就知
道沒有任何一個客戶端使用到自己,便
能夠將自己毀滅,
2015/7/17
6
COM元件的型態
視程式碼模組的結構以及元件與使用元件的
用戶端處理程序之間的關係而定,元件可分
為以下三種型態:
-行程內(In Process)
-本機(Local)
-遠端 (Remote)
2015/7/17
7
行程內(In-Process)
客戶端與伺服器端存在於相同的行程中,執行在相同的電腦上
2015/7/17
8
行程內(In-Process)
In-Process Server:DLL型式
執行時,將DLL載入記憶體區塊
容錯能力較差
執行於同一個Process,沒有安
全機制
2015/7/17
9
本機(Local)
本機伺服器和用戶端於相同的一部機器上,但是在另一個獨立的處理程序中執行
2015/7/17
10
本機(Local)
通常實作成 EXE 型式
不同行程,彼此不會互相干擾
Proxy-> Marshaling->IPC (inter-process
communication)->Un-marshaling->Stub
執行效率較 In-Process Server 差
2015/7/17
11
遠端(Remote)
客戶端與伺服器透過網路來溝通,執行於不同的電腦
2015/7/17
12
遠端(Remote)
Client端與 Server 端必須包含相對應的
proxy/stub 進行 marshaling
RPC(Remote Procedure Call) 溝通
Server端可為 DLL 型式或 EXE 型式
(若為 DLL,則需要 Server 的代理行程,
通常為 dllhost.exe)
2015/7/17
13
COM系統函式庫(COM Library)
COM系統層級的程式碼:COM的建置是包
含在COM系統函式庫中的。這項建置透
過一個DLL提供,這個DLL包含下列COM
的規格中所提到的要件:
-基本的API函數
-建置找尋服務
-透明化的遠端程序呼叫
-控制記憶體的配置
2015/7/17
14
介面定義語言(Interface Definition Language)
不需要任何的物件實作碼
MIDL(Microsoft IDL編譯器)
Proxy/Stub DLL :
Proxy和stub會被包在一個proxy/stub DLL
中,這個DLL包含客戶端proxy與伺服器
stub的程式碼 。當在不同的電腦上執行
客戶端與伺服器時,必須保證proxy/stub
DLL同時安裝及登錄在這兩台電腦 。
2015/7/17
15
COM物件的重複使用機制
收納(containment)
2015/7/17
16
COM物件的重複使用機制
聚集(aggregation)
2015/7/17
17
使用Visual Basic呼叫 Excel
Dim obj
Set obj = CreateObject(“Excel.Application”)
obj.visible = true
obj.Workbooks.Add
obj.Range("B3").Select
obj.ActiveCell.FormulaR1C1 = "12"
obj.Range("B4").Select
obj.ActiveCell.FormulaR1C1 = "34“
…
2015/7/17
18
COM 如何找出 Excel 的位置?
使用 RegEdit.exe 登錄編輯器
HKEY_CLASSES_ROOT
CLSID
{00024500-0000-000…}
LocalServer32 = excel.exe
Excel.Application
CLSID = {00024500-0000-000…}
Excel.Application : ProgID
2015/7/17
19
COM Runtime
元件和應用程式
COM Runtime
核心服務
(Monikers, Storage, Data Transfer,...)
[D]COM
Registry
MS-RPC
Pluggable Security
(SSPI)
Pluggable Transports
TCP
2015/7/17
UDP
IPX
Tunneled TCP
ETC...
NTLM DCE
Kerberos ETC...
20
Core COM Services
Security
Lifecycle
Management
Type Information
(Interface
Repository)
Monikers (Naming)
Automation
(Dynamic Invocation)
2015/7/17
Data Transfer
Component
Categories
Registry
21
COM Runtime Architecture
Flexible and extensible
Pluggable Transports
Proxy
TCP, UDP
SPX,IPX
Net BUI
HTTP
“Falcon”
COM Runtime
COM
Client
Server Machine
COM Runtime
Client Machine
Component
Other
Component
2015/7/17
22
COM Runtime Architecture
Flexible and extensible
Pluggable Security Providers
Proxy
NTLM
SSL, Certs.
NT Kerberos
DCE
COM Runtime
COM
Client
Server Machine
COM Runtime
Client Machine
Component
Other
Component
2015/7/17
23
COM 程式設計模型
用戶端程式
用戶端行程
OLE32.DLL
Service Control manager (RPCSS.EXE)
2015/7/17
24
COM 程式設計模型
用戶端程式
用戶端行程
OLE32.DLL
Object
元件行程
OLE32.DLL
Service Control manager (RPCSS.EXE)
2015/7/17
25
COM 程式設計模型
用戶端程式
proxy
用戶端行程
OLE32.DLL
Object
stub
元件行程
OLE32.DLL
Service Control manager (RPCSS.EXE)
2015/7/17
26
COM 程式設計模型
用戶端程式
proxy
Object
stub
用戶端行程
元件行程
OLE32.DLL
OLE32.DLL
Service Control manager (RPCSS.EXE)
2015/7/17
27
COM 程式設計模型
用戶端程式
COM 的
proxy
攔截機制
Object
stub
用戶端行程
元件行程
OLE32.DLL
OLE32.DLL
Service Control manager (RPCSS.EXE)
2015/7/17
28
Distributed COM
Just COM “with a longer wire”
All COM components communicate in the
same way

on the same machine
 In-process, Out-of-process



across a Local Area Network
across a Wide Area Network
across the Internet
Same tools, knowledge, code
Distributed COM
Wire Protocol

Based on DCE RPC Specification
 Interoperable with OSF DCE RPC
implementations

We call it “ORPC”
指定元件的伺服器的位置


2015/7/17
CreateObject(ProgID, “Jacky”)
DCOMCNFG.EXE
30
COM如何找到啟動遠端伺服器的資訊?
又是 RegEdit.exe!
HKEY_CLASSES_ROOT
AppID
{00024500-0000-000…}
RemoteServerName = jacky
2015/7/17
31
DCOM 的物件啟動
用戶端程式
Object
proxy
stub
用戶端行程
OLE32.DLL
元件行程
OLE32.DLL
SCM
SCM
Registry
{AppID}
2015/7/17
RemoteServerName
Registry
{CLSID}
LocalServer32
32
COM物件的安全模型
設定方式:
宣告式安全設定:於元件外部的登錄
(registry)中設定
程式控制安全設定:由程式設計者加進元件
宣告式安全設定:
預設安全(default security):指定所有在本機
上執行的元件之安全設定值
元件安全(component security):提供特別的
安全性給一個特定的元件
2015/7/17
33
Implementation With MFC(1)
To implement a class using MFC’s interface maps
follows these steps:
1.Use Derive a class either directly or indirectly from
CCmdTarget.
2.Use the DECLARE_INTERFACE_MAP function in
the derived class definition.
3.For each interface you wish to support, use the
BEGIN_INTERFACE_PART、
END_INTERFACE_PART
macros in the class definition.
2015/7/17
34
Implementation With MFC(2)
4.In the implementation file, use the
BEGIN_INTERFACE_MAP
and END_INTERFACE_MAP macros to define the class's
interface map.
5.For each IID supported, use the INTERFACE_PART macro
between the BEGIN_INTERFACE_MAP and
END_INTERFACE_MAP macros to map that IID
to a specific "part" of your class.
2015/7/17
35
Implementation With MFC(3)
6.Implement each of the nested classes that represent the
interfaces you support.
7.Use the METHOD_PROLOGUE macro to access the parent,
CcmdTarget-derived object.
8.AddRef, Release, and QueryInterface can delegate to the
CcmdTarget implementation of these functions:
ExternalAddRef, ExternalRelease, and
ExternalQueryInterface.
2015/7/17
36
Macro of MFC Implementation(1)
BEGIN_INTERFACE_PART(localClass, iface);
END_INTERFACE_PART(localClass)
localClass:實作 interface 的 class
iface:class 實作的 interface
用來產生巢狀類別,它會把X加到第一個參數
名稱前,以組成類別名稱。
2015/7/17
37
Macro of MFC Implementation(2)
DECLARE_INTERFACE_MAP
產生一個表格的宣告,這個表格內含所有類別的介面
識別碼
BEGIN_INTERFACE_MAP(theClass, baseClass)
END_INTERFACE_MAP
theClass :要建立 interface 的 class
baseClass:該 class所繼承的類別
在implement時,實際定義 interface map。
2015/7/17
38
Macro of MFC Implementation(3)
STDMETHOD_
在宣告敘述(*.h file)中,宣告method。
STDMETHODIMP_
在implement中(*.cpp),定義method。
此兩巨集將傳回值指定為第一個參數。
2015/7/17
39
Macro of MFC Implementation(4)
STDMETHOD
在宣告敘述(*.h file)中,宣告method。
STDMETHODIMP
在implement中(*.cpp),定義method。
此兩巨集採用型態為HRESULT的傳回值。
METHOD_PROLOGUE
傳回父類別的指標,且存於pThis這個指標中。
2015/7/17
40
CLASS FACTORY(1)
A COM object that implements the
IClassFactory interface and that creates
one or more instances of an object。
2015/7/17
41
CLASS FACTORY(2)
IClassFactory介面:
衍生自IUnknow介面,主要member function
為:
virtual BOOL CreateInstance(int& nlid,
void** ppvObj)
=0
2015/7/17
42
CLASS FACTORY(3)
Why Class Factory ?
因為不能直接call target class的constructor,
則object的設置和啟動是透過Class Factory
來作。
2015/7/17
43
介面宣告 Interface.h
struct Isum : public IUnknown
{
STDMETHOD_(void, Sum) (int x,int y,
int *revtal) = 0;
};
2015/7/17
44
由CcmdTarget類別derived下來的
元件類別 test.h
class CTest : public CCmdTarget
{

protected:

BEGIN_INTERFACE_PART(Sum, ISum)
STDMETHOD_(void, Sum) (int x,int y,int *revtal);
END_INTERFACE_PART(Sum)
DECLARE_INTERFACE_MAP()
};
2015/7/17
45
類別implement test.cpp(1)
#include "Interface.h"
#include "test.h“

static const IID IID_ISum =
{ 0x692d03a4, 0xc689, 0x11ce,
{ 0xb3, 0x37, 0x88, 0xea, 0x36, 0xde, 0x9e, 0x4e } };
BEGIN_INTERFACE_MAP(CTest, CCmdTarget)
INTERFACE_PART(CTest, IID_ISum, Sum)
END_INTERFACE_MAP()
2015/7/17
46
類別implement test.cpp(2)
STDMETHODIMP_(ULONG) CTest::XSum::AddRef()
{
METHOD_PROLOGUE(CTest, Sum)
return pThis->ExternalAddRef();
}
STDMETHODIMP_(ULONG) CTest::XSum::Release()
{
METHOD_PROLOGUE(CTest, Sum)
return pThis->ExternalRelease();
}
2015/7/17
47
類別implement test.cpp(3)
STDMETHODIMP CTest::XSum::QueryInterface(
REFIID iid, LPVOID* ppvObj)
{
METHOD_PROLOGUE(CTest, Sum)
return pThis->ExternalQueryInterface(&iid, ppvObj);
}
STDMETHODIMP_(void) CTest::XSum::Sum(int x,int
y,int *revtal)
{
*revtal=x+y;
return;
}
2015/7/17
48
用戶端程式(1):
LPCLASSFACTORY pClf;
LPUNKNOWN pUnk;
ISum* pSum;
Imultilpy *pMul
HRESULT hr;
CLSID clsid;
if ((hr = ::CLSIDFromProgID(L"Test", &clsid)) !=
NOERROR) {
return; }
2015/7/17
49
用戶端程式(2):
if((hr=::CoGetClassObject(clsid,CLSCTX_REMOTE_SERV
ER, NULL, IID_IClassFactory, (void **) &pClf)) !=
NOERROR)
{;
return;
}
pClf->CreateInstance(NULL, IID_IUnknown, (void**)
&pUnk);
pUnk->QueryInterface(IID_ISum, (void**) &pSum);
2015/7/17
50
用戶端程式(3):
int sum;
pSum->Sum(4,5,&sum);
pClf->Release();
pUnk->Release();
pSum->Release();
2015/7/17
51
DCOM Component Connector
由SAP與Microsoft共同利用DCOM研發出來
的架構,可以讓由SAP或其他公司所提供的
components完美、緊密地的結合;而且藉由先
前定義好的界面,可以輕易地昇級系統的某個元
件(component),而不是一次就須換整個系統。
2015/7/17
52
使用DCOM Component Connector的好處(1)
A new dimension of openness
透過定義良好的 interface 可輕易地補強和擴充
Leverage existing programming skills
未來的補強工具可在SAP tools和COM tools之間作
選擇
2015/7/17
53
使用DCOM Component Connector的好處(1)
Eased integration
因為使用了DCOM,與其他產品的整合變得容易
甚至可以使用多種不同的DataBases
Evolutionary approach
因具有良好的scalability,可依需求增加硬體等方
面作漸進的補強
2015/7/17
54
發展現況
SAP利用DCOM Component Connector 發展
了Business Framework,提供一個componentbased、integrated、open application software
solution。而目前SAP主推的collaborative ebusiness平台mySAP.com 正是用Business
Framework為基礎所形成的。
2015/7/17
55
Thank you!
2015/7/17
56