.NET Remoting安全性问题

在.NET framework 1.1中,只支持在IIS为宿主,并使用HTTP信道时才可以有内置的安全支持。而使用TCP信道时,则要自己写程序才可以。 不过,这在.NET Framework 2.0中得到了改进。现在TCP Channel也可以实现内置的安全功能。不过,MSDN给出的文档很少。都不知道是什么原理以及如何有效的使用。不知道现在的网上有没有什么大侠可以指点一下。呵呵。

在以前的MSDN杂志有两篇文章介绍了一下.net Remoting的安全解决方案。现在还没有看完。希望有点帮助吧

UPdate 2006-05-08

经过测试,了解了一些TCP Channel配置属性。在MSDN中也说明了。只是我没有试过,也没有讲过具体的运作方式,所有心里没有底。

在写了一个例子程序,然后将Remoting 客户端与服务器端的TcpChannel的配置加入属性。

客户端代码:

                IDictionary myDic = new Hashtable();
                myDic["name"] = "MyTcpClient";
                myDic["port"] = 0;
                myDic["impersonationLevel"] = "Identify";
                myDic["tokenImpersonationLevel"] = "Identification";
                myDic["secure"] = true; //进行加密标识,上面两个标识是加密所必须的。进行证书交换
                myDic["username"] = "guest"; // 在不以域组的网络上,如果不加用户名与密码时,会出现认证不过的情况
                myDic["password"] = "";

                BinaryServerFormatterSinkProvider bsp = new BinaryServerFormatterSinkProvider();
                bsp.TypeFilterLevel = TypeFilterLevel.Full;

                BinaryClientFormatterSinkProvider bcp = new BinaryClientFormatterSinkProvider();

                TcpChannel chnl = new TcpChannel(myDic, bcp, bsp);

                ChannelServices.RegisterChannel(chnl, false);

                myHello = (CardGameLib.HelloWorld)Activator.GetObject(typeof(CardGameLib.HelloWorld),
                    "tcp://localhost:2234/HelloWorld.rem");

服务器代码要简单一点。

            IDictionary myDic = new Hashtable();
            myDic["port"] = 2234;
            myDic["name"] = "MyTcpServer";
            myDic["authenticationMode"] = "identifyCallers";
            myDic["tokenImpersonationLevel"] = "Identification";
            myDic["secure"] = true;

            BinaryServerFormatterSinkProvider bsp = new BinaryServerFormatterSinkProvider();
            bsp.TypeFilterLevel = TypeFilterLevel.Full;

            BinaryClientFormatterSinkProvider bcp = new BinaryClientFormatterSinkProvider();

            TcpChannel chnl = new TcpChannel(myDic, bcp, bsp);

            ChannelServices.RegisterChannel(chnl, false);

            RemotingConfiguration.RegisterWellKnownServiceType(typeof(MyHelloWorld),
                "HelloWorld.rem", WellKnownObjectMode.Singleton);

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值