Ich kriegs nicht hin, hier mal mein Test-Code, kann da jemand mal drüberschauen, was ich falsch mache?
Vielen Dank!
Anwendung 1 (Server und Client):
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Ipc
Module Module1
Sub Main()
Dim ipcCh As IpcChannel
ipcCh = New IpcChannel("Server")
ipcCh.IsSecured = True
ChannelServices.RegisterChannel(ipcCh, False)
RemotingConfiguration.RegisterWellKnownServiceType( _
GetType(CommunicationService), "SreeniRemoteObj", _
WellKnownObjectMode.Singleton)
Console.ReadLine()
End Sub
End Module
Imports System.Runtime.InteropServices
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Ipc
Public Class CommunicationService
Inherits MarshalByRefObject
Implements SharedInterfaces.ICommunicationService
Public Sub SaySomething(ByVal text As String) Implements _
SharedInterfaces.ICommunicationService.SaySomething
Dim ipcCh As New IpcChannel("Client2")
ipcCh.IsSecured = True
'Hier kommt der Fehler: Der Channel "ipc" wurde bereits registriert.
ChannelServices.RegisterChannel(ipcCh, False)
Dim obj As SharedInterfaces.ICommunicationService = _
DirectCast(Activator.GetObject(GetType( _
SharedInterfaces.ICommunicationService), _
"ipc://Answer/SreeniRemoteObj"), _
SharedInterfaces.ICommunicationService)
obj.SaySomething(text)
ChannelServices.UnregisterChannel(ipcCh)
End Sub
End Class Anwendung 2 (Client, sendet an Anwendung 1):
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Ipc
Public Class Form1
Private Sub cmdSend_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles cmdSend.Click
Dim ipcCh As New IpcChannel("Client")
ipcCh.IsSecured = True
ChannelServices.RegisterChannel(ipcCh, False)
Dim obj As SharedInterfaces.ICommunicationService = _
DirectCast(Activator.GetObject(GetType( _
SharedInterfaces.ICommunicationService), _
"ipc://Server/SreeniRemoteObj"), _
SharedInterfaces.ICommunicationService)
obj.SaySomething(TextBox1.Text)
ChannelServices.UnregisterChannel(ipcCh)
End Sub
End Class Anwendung 3 (Server, empfängt von Anwendung 1):
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Ipc
Module Module1
Sub Main()
Dim ipcCh As IpcChannel
ipcCh = New IpcChannel("Answer")
ipcCh.IsSecured = True
ChannelServices.RegisterChannel(ipcCh, False)
RemotingConfiguration.RegisterWellKnownServiceType( _
GetType(CommunicationService), "SreeniRemoteObj", _
WellKnownObjectMode.Singleton)
Console.ReadLine()
End Sub
End Module
Imports System.Runtime.InteropServices
Public Class CommunicationService
Inherits MarshalByRefObject
Implements SharedInterfaces.ICommunicationService
Public Sub SaySomething(ByVal text As String) Implements _
SharedInterfaces.ICommunicationService.SaySomething
Console.WriteLine(text)
End Sub
End Class
Beitrag wurde zuletzt am 16.06.10 um 18:52:06 editiert. |