.NET开发

本类阅读TOP10

·NHibernate快速指南(翻译)
·vs.net 2005中文版下载地址收藏
·【小技巧】一个判断session是否过期的小技巧
·VB/ASP 调用 SQL Server 的存储过程
·?dos下编译.net程序找不到csc.exe文件
·通过Web Services上传和下载文件
·学习笔记(补)《.NET框架程序设计(修订版)》--目录
·VB.NET实现DirectDraw9 (2) 动画
·VB.NET实现DirectDraw9 (1) 托管的DDraw
·建站框架规范书之——文件命名

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
也谈 DotNet Remoting 中的事件处理

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

有朋友提到了在Remoting 中的事件处理的问题,我 google 了一下,发现几篇有用的文章。

大坏蛋 的 Dotnet Remoting 事件处理
http://blog.joycode.com/joe/archive/2004/11/09/38437.aspx

创建以Microsoft .NET Remoting为基础的分布式应用架构
卢彦
http://www.microsoft.com/china/community/Column/62.mspx

思路很简单,如果你去模仿写一个的话,还是很容易出错。

大概思想:
所谓事件的订阅发布模型,有一个前提就是程序必须是有状态的。这一点很重要,就应为这一点所以 http web service 无法直接实现事件模型。

对于Remoting 的事件,也必须保证远程对象是有状态的。
所以如果你用服务端激活的话,必须为 Singleton 模型。singlecall 的话,你会发现程序调试没有问题。事件处理程序言根儿就轮不到执行:)

初学者很容易碰到 一下错误

An unhandled exception of type 'System.Security.SecurityException' occurred in mscorlib.dll

Additional information: Type System.DelegateSerializationHolder and the types derived from it (such as System.DelegateSerializationHolder) are not permitted to be deserialized at this security level.

这个问题大坏蛋解释过了,只要在程序中配置或者硬编码设置服务端 ChannelSink 中 Formatter 信道的 TypeFilterLevel 为Full 就可以了。

比如一下代码
vb.net

         Dim chan2 As HttpChannel
            chan2 
= New HttpChannel(8086)

            
Dim ic As IServerChannelSink = chan2.ChannelSinkChain
            
While Not (ic Is Nothing)

                
If TypeOf (ic) Is SoapServerFormatterSink Then
                    
CType(ic, SoapServerFormatterSink).TypeFilterLevel = Runtime.Serialization.Formatters.TypeFilterLevel.Full
                
End If
                
If TypeOf (ic) Is BinaryServerFormatterSink Then
                    
CType(ic, BinaryServerFormatterSink).TypeFilterLevel = Runtime.Serialization.Formatters.TypeFilterLevel.Full
                
End If
                ic 
= ic.NextChannelSink
            
End While

C#

            HttpChannel chan2 = new HttpChannel(8086);

            IServerChannelSink sc
=chan2.ChannelSinkChain;
            
while(sc!=null)
            
{
                
if(sc is BinaryServerFormatterSink)
                
{
                    ((BinaryServerFormatterSink)sc).TypeFilterLevel
=TypeFilterLevel.Full;
                }


                
if(sc is SoapServerFormatterSink)
                
{
                    ((SoapServerFormatterSink)sc).TypeFilterLevel
=TypeFilterLevel.Full;
                }


                sc
=sc.NextChannelSink;
            }



当然是服务端设置一下就可以了

还有一个容易犯的错误就是:

n unhandled exception of type 'System.Runtime.Remoting.RemotingException' occurred in mscorlib.dll

Additional information: This remoting proxy has no channel sink which means either the server has no registered server channels that are listening, or this application has no suitable client channel to talk to the server.



这个只要把客户端的 channel端口号改为0 ,让系统随意"折腾"即可。

            Dim chan As HttpChannel
            chan = New HttpChannel(0




相关文章

相关软件