|
鄭重聲明:本帖是作者原創(chuàng),轉(zhuǎn)載請(qǐng)注明作者,讓俺也沽名釣譽(yù)一把,嘿嘿
前一段時(shí)間一直在做OPCAE的服務(wù)器端和客戶端的開發(fā),在開發(fā)的過(guò)程中碰到了一個(gè)問(wèn)題。要求連接的是siemens sipass的opc AE,sipass做客戶端,我做服務(wù)器,發(fā)送報(bào)警信息。開發(fā)完了以后,先運(yùn)行服務(wù)器程序,然后再用客戶端來(lái)連接,連接不上,很是奇怪,因?yàn)橛脛e的客戶端來(lái)連接都可以連接上,查看進(jìn)程管理器,發(fā)現(xiàn)存在兩個(gè)服務(wù)器進(jìn)程,這是為什么呢?明明做了進(jìn)程互斥了,并且
RegisterClassObjects(CLSCTX_LOCAL_SERVER, //Registers the class factory in the Running Object Table.
REGCLS_MULTIPLEUSE);
也使用了REGCLS_MULTIPLEUSE參數(shù),為什么還是會(huì)出現(xiàn)這樣的問(wèn)題呢。網(wǎng)上到處翻帖子也沒有結(jié)論,都說(shuō)使用了REGCLS_MULTIPLEUSE就應(yīng)該只初始化一個(gè)實(shí)例,但事實(shí)上確實(shí)存在著兩個(gè)實(shí)例。后來(lái)仔細(xì)觀察任務(wù)管理器發(fā)現(xiàn),兩個(gè)進(jìn)程的用戶名一個(gè)是當(dāng)前用戶的,一個(gè)是system的,于是就懷疑,是不是因?yàn)橛脩舨煌瑢?dǎo)致實(shí)例化了兩個(gè)進(jìn)程呢,盡管使用了REGCLS_MULTIPLEUSE參數(shù),道微軟的網(wǎng)站發(fā)現(xiàn)了一個(gè)帖子原文很長(zhǎng),附上一小段,大概的意思是,每個(gè)用戶對(duì)于com的服務(wù)都有安全環(huán)境上下文,是否使用存在的進(jìn)程,跟設(shè)備環(huán)境上下文關(guān)系很密切,
When a client requests a class object for a registered class, COM either returns an existing class object or launches a process that is registered as containing the requested class object. The process of obtaining a class object reference for a requesting client (whether or not that results in process creation or "launching") is called "activation."
Under certain conditions, COM may launch a new server process even when an existing class object is running and has been registered as multiple use. Moreover, when COM creates a new process that process may be launched in a new security environment known as a "window station" rather than sharing an existing window station such as the interactive window station. (For more information on window stations, search the Win32 SDK documentation for that phrase.)
Understanding COM's algorithms for creating new processes and window stations during an activation request is important for several reasons. First, COM may create more than one process instance of a multiple-use class object because of security issues. Second, "single-use" servers will always be launched in separate processes, but they may or may not be launched in separate window stations. This difference might manifest itself to application code in certain unusual cases, such as when two COM servers try to communicate via window messages or secure communication facilities such as COM or RPC. Third, since the number of window stations that can simultaneously be created in Windows NT is limited, it is important to know when your COM server gets a new window station.
This article examines different activation scenarios and explains when new processes and window stations are created.
其實(shí)解決問(wèn)題的方法非常的簡(jiǎn)單,就是設(shè)置成交互式用戶就可以了,這是做DCOM配置的時(shí)候畢設(shè)的一項(xiàng),但是在配置的時(shí)候,沒有去琢磨,為什么這樣設(shè)置,原來(lái)是基于設(shè)備安全環(huán)境上下文相關(guān),仔細(xì)閱讀了微軟的這篇文章,就明白了很多的東西,尤其原來(lái)在DCOM設(shè)置,網(wǎng)絡(luò)OPC經(jīng)常不通的原因也就很明了了
微軟原文連接地址:http://support.microsoft.com/kb/169321/en-us
希望一點(diǎn)小經(jīng)驗(yàn),對(duì)大家理解COM和opc有所幫助
|
|