VB.NET Remoting
Visual Basic
1
Posts
1
Posters
0
Views
1
Watching
-
I have been searching for simple examples of how to do remoting with VB.NET. What I desire is a remoting object that exposes some shared functions to return other objects. I am currently using console applications as my test environment. Here is my object that should be created by the shared function and returned to the client.
<Serializable()> _ Public Class SampleObject Private mName Private mData Public Sub New() Console.WriteLine("Object Created") End Sub Public Property Name() As String Get Return mName End Get Set(ByVal Value As String) mName = Value End Set End Property Public Property Data() As String Get Return mData End Get Set(ByVal Value As String) mData = Value End Set End Property Public Overrides Function ToString() As String Return mName & " " & mData End Function End Class
Now, my server has a class that will populate the object:
Public Class Creator Inherits MarshalByRefObject Public Shared Function CreateSampleObject() As RemotingObject.SampleObject Dim NewObj As New RemotingObject.SampleObject NewObj.Name = "Hello" NewObj.Data = "World" Return NewObj End Function End Class
The problem is that I do not understand where the Creator needs to be. Does a reference need to exist in both the client and server? If not, how do I activate a class of the object. Here is my server console application:
Imports System.Runtime.Remoting Imports System.Runtime.Remoting.Channels Imports System.Runtime.Remoting.Channels.Tcp Module Server Sub Main() RemotingConfiguration.ApplicationName = "Server" RemotingConfiguration.RegisterWellKnownServiceType( _ GetType(Creator), "object.rem", _ WellKnownObjectMode.SingleCall) Dim mChannel As New TcpChannel(1441) ChannelServices.RegisterChannel(mChannel) mChannel.StartListening(Nothing) Console.WriteLine("Listening on port: 1441") Console.ReadLine() mChannel.StopListening(Nothing) End Sub End Module
Finally, the client (as it stands right now -- and it doesn't work)
Imports System.Runtime.Remoting Imports System.Runtime.Remoting.Channels Imp