How to write a DCOM server in C# 如何用C#编写DCOM服务器

先讲讲.net Remoting与DCOM的区别:.net Remoting 是在DCOM等基础上发展起来的一种技术,它的主要目的是实现跨平台、跨语言、穿透企业防火墙。DCOM是通过TCP/IP通道安全的进程间通信,而.NET remoting 不是。任何进程包括windows服务都能寄宿在DCOM服务器中。

如果你已经十分清楚地知道了COM的话,可以参考下面的几点加深你对DCOM的了解。

1) Your server process will expose a COM class factory that would just create your .NET object.

    你的DCOM服务器进程应该暴露一个COM类工厂以便于创建.net对象

2) In COM you register the class factory using the standard CoRegisterClassObjects API 。

    在COM中尼应该使用标准的API(CoRegisterClassObjects函数)注册类工厂。

3) Make sure you call CoInitializeSecurity on your first process, for example to allow only Administrators to call in 。

   确认在第一个进程中调用CoInitializeSecurity函数,例如尽允许在具有管理员的主机上调用。

4) Register your .NET assemblies with REGASM.EXE. Make sure your .NET class is visible through COM so CCW can be created around it (more details in MSDN on COM Interop section).

    使用REGASM.EXE工具注册.net汇编程序,确认你的.netleu通过COM组件后可见,以便于可以创建CCW。

5) Remove the auto-generated InprocServer32 key after registration (REGASM puts it there but we are going out-of-proc)

  完成注册后移除自动产生的InprocServer32 key。

6) Add the standard LocalServer32 / AppID registry keys.

   添加标准的LocalServer32 / AppID的注册表键值。

下面是注册的CMD批处理脚本:

 

 

 

And a test VBS script that will exercise our service from a separate process obviously:

 

通过一个独立进程的VBS测试脚本来实践我们的服务

 

One more comment: The code above allows everybody to call into the process. This is probably not very useful since you might want to allow only administrators to call into your service. There is a solution though: all you have to do is to pass a certain security descriptor to CoInitializeSecurity that will allow only certain classes of users to call into the process. This is actually not very hard, and I'll probably post a sample code in the future. Now I have to get back to work, so see you for the next time!

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值