@@@@###高难度问题:.net Remoting中在远程应用程序之间传递事件**********

mulintaomulintao 2005-03-19 08:59:27
本人好长时间都没解决的问题:


////////////////////////////////////
类库一:

Imports System.Runtime.Remoting.Messaging

Public Delegate Sub OutputDelegate(ByVal sender As Object, ByVal args As EventArgs)

'>>>>>>>>>>MyEventArgs类
<Serializable()> Public Class MyEventArgs
Inherits EventArgs

Private _contribution As String

Public Sub New(ByVal contribution As String)
_contribution = contribution
End Sub

Public ReadOnly Property Contribution()
Get
Return _contribution
End Get
End Property

End Class

'>>>>>>>>Conference类
Public Class Conference
Inherits MarshalByRefObject

Public Event TheDelegate As OutputDelegate

Sub Input(ByVal contribution As String)
Console.WriteLine("Input received:<{0}>", contribution)
Dim args As New MyEventArgs(contribution)
RaiseEvent TheDelegate(Me, args)
End Sub

End Class

'>>>>>>>>>抽象基类,可远程委托
Public MustInherit Class RemotelyDelegatableObject
Inherits MarshalByRefObject

Sub ExternalCallback(ByVal sender As Object, ByVal args As EventArgs)
InternalCallback(sender, args)
End Sub

Protected MustOverride Sub InternalCallback(ByVal sender As Object, ByVal args As EventArgs)

End Class

//////////////////////////////////////////////
类库二:(引用类库一)
Imports Conference

Public Class ConfAttendee
Inherits RemotelyDelegatableObject


Public Sub Run()
Dim strurl As String
Dim myConference As Conference.Conference
Dim contribution As String
Dim name As String
Dim nickName As String

strurl = "tcp://localhost:10000/MyConference.rem"
myConference = CType(Activator.GetObject(GetType(Conference.Conference), strurl), Conference.Conference)
AddHandler myConference.TheDelegate, AddressOf ExternalCallback

While True
Console.WriteLine("Input?----")
contribution = Console.ReadLine()
If contribution.Length = 0 Then
Exit While
End If

myConference.Input(contribution)
End While

RemoveHandler myConference.TheDelegate, AddressOf ExternalCallback
End Sub

Protected Overrides Sub InternalCallback(ByVal sender As Object, ByVal args As EventArgs)
Dim myArgs As MyEventArgs
myArgs = CType(args, MyEventArgs)
Console.WriteLine("Input received:<{0}>", myArgs.Contribution())
End Sub

End Class

///////////////////////////////////////////////////////////////////
客户端:

'
'客户端应用程序
'


Imports System
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Tcp


Module Module1

Sub Main()

Dim command As String
Dim port As Integer

command = Microsoft.VisualBasic.Command

If command.Length = 0 Then
port = 10001
Else
port = CInt(command)
End If

Dim channel As TcpChannel
channel = New TcpChannel(port)
ChannelServices.RegisterChannel(channel)

Dim attendee As New ConfAttendee.ConfAttendee
attendee.Run()

End Sub

End Module

/////////////////////////////////////////////////////////////////
服务器端:

'
'服务器端程序
'

Imports System
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Tcp

Module Module1

Sub Main()
Dim channel As TcpChannel
Console.WriteLine("Server started!-----------")

channel = New TcpChannel(10000)
ChannelServices.RegisterChannel(channel)
RemotingConfiguration.RegisterWellKnownServiceType(GetType(Conference.Conference), "MyConference.rem", WellKnownObjectMode.Singleton)

Console.ReadLine()
End Sub

End Module
//////////////////////////////////////////////////////////////////

错误:

不允许类型 System.DelegateSerializationHolder 和从中派生的类型(例如 System.DelegateSerializationHolder)在此安全级别上被反序列化。

那位大哥帮忙解决问题,分全给他

...全文
118 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Montaque 2005-03-21
  • 打赏
  • 举报
回复
解决了吗? 跟 windows 2003 没有关系的
Montaque 2005-03-19
  • 打赏
  • 举报
回复
修改一下channel 的属性就可以了.

参考我的blog http://www.cnblogs.com/montaque/archive/2004/11/17/64670.aspx
mulintaomulintao 2005-03-19
  • 打赏
  • 举报
回复
是不是2003不能处理远程事件?真怀疑啊
mulintaomulintao 2005-03-19
  • 打赏
  • 举报
回复
属性我按照要求改了,可还是不行啊

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

是不是加上这些?
mulintaomulintao 2005-03-19
  • 打赏
  • 举报
回复
问题还是不行啊

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧