也谈 DotNet Remoting 中的事件处理
2004-11-17 10:13
411 查看
有朋友提到了在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)
当然是服务端设置一下就可以了
还有一个容易犯的错误就是:
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)
大坏蛋 的 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)
当然是服务端设置一下就可以了
还有一个容易犯的错误就是:
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)
相关文章推荐
- [转]SQL优化较高境界
- 在Visual Baisc.NET 2005中使用泛型
- vpopmail 和qmailadmin的配置
- 偶的CSDN收藏夹(大部分都是古董……)
- asp.net Datagrid 资源
- 使用vpopmail的domainquotas功能
- 通过svc实现连接的配置
- :[百万级]通用存储过程.分页存储过程..返回指定返回条数、指定页数的记录
- 开发对帐系统续
- 好久不来这里了
- 开篇语
- 设计模式学习笔记
- Struts学习笔记
- RMagick 1.6.1 发布
- 读“刘翔千万元广告收入分配“大餐”名单漏了谁”感
- 连接ftp服务器,进行上传下载
- Winform中的配置文件与动态属性
- 这几天郁闷的事真多
- 这几天郁闷的事真多
- 使用xmlhttp为网站增加域名查询功能