@@@@###高难度问题:.net Remoting中在远程应用程序之间传递事件**********
本人好长时间都没解决的问题:
////////////////////////////////////
类库一:
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)在此安全级别上被反序列化。
那位大哥帮忙解决问题,分全给他