Dealing with .NET Enterprise Services: .NET Remoting, Web Services and Service Components - Working with the Remoting Client and Remoting Object
(Page 2 of 6 )
Now let us go through the code of the Remoting Client.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Dim chan As New TcpChannel
ChannelServices.RegisterChannel(chan)
Dim obj As HelloServer = _
CType(Activator.GetObject(GetType(HelloServer), _
"tcp://localhost:8085/SayHello"), HelloServer)
Try
MessageBox.Show(obj.HelloMethod(Me.TextBox1.Text))
Catch ex As Exception
MessageBox.Show("Server could not be located or
communication error")
End Try
ChannelServices.UnregisterChannel(chan)
End Sub
You can clearly observe from the above program that the client is trying to contact through the “tcp” protocol (and that too at the 8085 port) with the service name “SayHello.” Once the client receives the proxy of the server remote object, it can directly execute the methods (“HelloMethod”), as if they are locally available.
Considering the issue of the “RemoteObject,” it is simply a class which is used for distributed programming. It is defined as follows within the solution:
Imports System
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Tcp
Public Class HelloServer
Inherits MarshalByRefObject
Public Function HelloMethod(ByVal name As String) As String
Return "Hi there, " & name
End Function
End Class
Every “RemoteObject” (or the class used by the Remoting server to create and share with clients) should be extended from “MarshalByRefObject” (just to give “remote” access).
Next: Working with a basic COM application >>
More .NET Articles
More By Jagadish Chaterjee