Hallo,
habe jetzt alles zum Laufen gebracht, bis auf die Events. Bekomme da immer eine Serialization Exception:
Server:
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Tcp
Imports Remote
Public Class Main
Const DefaultPort As Integer = 12345
Public Shared Sub Main(ByVal args() As String)
Dim props As IDictionary = New Hashtable
props("typeFilterLevel") = "Full"
props("port") = DefaultPort
props("rejectRemoteRequests") = True
Dim serverProv As BinaryServerFormatterSinkProvider = New _
BinaryServerFormatterSinkProvider(props, Nothing)
serverProv.TypeFilterLevel = _
System.Runtime.Serialization.Formatters.TypeFilterLevel.Full
Dim clientProv As BinaryClientFormatterSinkProvider = New _
BinaryClientFormatterSinkProvider
Dim serverChannel As TcpChannel = New TcpChannel(props, clientProv, _
serverProv)
ChannelServices.RegisterChannel(serverChannel)
'ChannelServices.RegisterChannel(New TcpChannel(DefaultPort))
RemotingConfiguration.RegisterWellKnownServiceType(GetType( _
Remote.RemotingClass), "RemotingClass", WellKnownObjectMode.Singleton)
Console.WriteLine("Server is running...")
Console.ReadLine()
Console.WriteLine("Server is shutting down...")
End Sub
End Class RemotingClass.vb in einer neue Klassenbibliothek Remote.vbproj
Imports System
<Serializable()> _
Public Class RemotingClass
Inherits System.MarshalByRefObject
Public Overrides Function InitializeLifetimeService() As Object
Return Nothing
End Function
Private m_SharedText As String
Public Event UpdateEvent()
Public Property SharedText() As String
Get
SharedText = m_SharedText
End Get
Set(ByVal Value As String)
m_SharedText = Value
End Set
End Property
Public Sub RaiseEventHandler()
RaiseEvent UpdateEvent()
End Sub
Private Sub New()
End Sub
End Class Client:
Const DefaultPort As Integer = 12345
Private s_dx As Remote.RemotingClass
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Try
ChannelServices.RegisterChannel(New TcpChannel)
s_dx = CType(Activator.GetObject(GetType(Remote.RemotingClass), _
String.Format("tcp://localhost:{0}/{1}", DefaultPort, _
"RemotingClass")), Remote.RemotingClass)
AddHandler s_dx.UpdateEvent, AddressOf UpdateEvent
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Private Sub UpdateEvent()
MsgBox("event raised")
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Button2.Click
Label1.Text = s_dx.SharedText
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Button1.Click
s_dx.SharedText = TextBox1.Text
End Sub Da haben sich auch schon andere den Kopf zerbrochen, aber eine Lösung für mein Beispiel habe ich noch nicht gefunden.
http://www.dotnet247.com/247reference/msgs/45/228224.aspx
Danke!!!! |