Ja, bis du die Methode aufrufst gibt's noch keine Verbindung zum Server. Und der Fehler kann viele Gründe haben. Ich habe drei kleine Projekte angelegt mehr oder weniger nach deiner Speizifkation und das klappt.
Interface:
Public Interface IAuthenticationClass
Function Login(ByVal user As String, ByVal pw As String) As String
End Interface] Klasse
Public Class AuthenticationClass
Inherits MarshalByRefObject
Implements IAuthenticationClass
Public ref As Object
Public Function Login(ByVal user As String, ByVal pw As String) As String _
Implements IAuthenticationClass.Login
MsgBox("User: " & user & " with password: " & pw & " attempting logon")
Return "Id0001"
End Function
End Class beide im Projekt "Common"
Hier ist der Client
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.tcp
Imports Common
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Private _port As Integer = 10240
Private _authentication As IAuthenticationClass
Private _channel As TcpClientChannel
Private _UserID As String
Private Sub ConnectToWinControl()
_channel = New TcpClientChannel
ChannelServices.RegisterChannel(_channel)
Dim URI As String = "tcp://localhost:" & _Port.ToString & _
"/Authentication"
_Authentication = CType(Activator.GetObject(GetType( _
IAuthenticationClass), URI), IAuthenticationClass)
_UserID = _Authentication.Login("Admin", "Paebbels")
End Sub
Private Sub ConnectButton_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles ConnectButton.Click
ConnectToWinControl()
End Sub
End Class und hier Der Server
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.tcp
Imports Common
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Private Sub StartButton_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles StartButton.Click
RegisterAuthenticationClass()
End Sub
Private _channel As Tcp.TcpServerChannel
Private _port As Integer = 10240
Private authentication As AuthenticationClass
Private _RObj As ObjRef
Private Sub RegisterAuthenticationClass()
_Channel = New Tcp.TcpServerChannel(_Port)
ChannelServices.RegisterChannel(_Channel)
Authentication = New AuthenticationClass
Authentication.Ref = Me
_RObj = RemotingServices.Marshal(Authentication, "Authentication", _
GetType(IAuthenticationClass))
End Sub
End Class ________
Alle Angaben ohne Gewähr. Keine Haftung für Vorschläge, Tipps oder sonstige Hilfe, falls es schiefgeht, nur Zeit verschwendet oder man sonst nicht zufrieden ist |