Help with my .net remoting code!

karthik_raja

New member
Joined
Feb 6, 2008
Messages
2
Programming Experience
Beginner
hi friends, i have written a simple addition using .net remoting. but i am getting an error.
can u plz tell me wat is the problem in my code. i am a beginner so bare with me.:)

dll object

VB.NET:
Imports System
Imports System.IO

Public Interface calc
    Sub add(ByVal a As Integer, ByVal b As Integer)
    Function getvalue() As Integer
End Interface
server object

VB.NET:
Imports System
Imports System.IO
Imports System.Runtime
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Http
Imports calc



Module Server
    Public Class Server
        Inherits MarshalByRefObject
        Implements calc.calc


        Dim sum As Integer

        Public Shared Sub Main()
            Dim sc As New HttpChannel(8080)

            ChannelServices.RegisterChannel(sc, False)

            RemotingConfiguration.RegisterWellKnownServiceType(GetType(Server), "server.soap", WellKnownObjectMode.SingleCall)
            Console.WriteLine("server started, press Enter to exit...")
            Console.ReadLine()
        End Sub

        Public Sub setvalue(ByVal a As Integer, ByVal b As Integer) Implements calc.calc.add
            sum = a + b
        End Sub

        Public Function getvalue() As Integer Implements calc.calc.getvalue
            Return sum
        End Function

    End Class
End Module

client object

VB.NET:
Imports System
Imports System.IO
Imports System.Runtime
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Http
Imports calc




Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim cch As New HttpChannel
        Dim sum, check As Integer
        check = 0

        ChannelServices.RegisterChannel(cch, False)
        Dim obj As calc.calc = CType(Activator.GetObject(GetType(calc.calc), "http://localhost:8080/Server.Server.soap"), calc.calc)
        Label1.Text = "connected to remote server"
        If (Label1.Text = "connected to remote server") Then
            check = 1
        End If

        If (check = 1) Then
            Dim a, b As Integer

            a = TextBox1.Text
            b = TextBox2.Text
            obj.add(a, b)                      ====>error
            sum = obj.getvalue()    ====>error
            TextBox3.Text = sum
        End If
end sub
end class
i have added reference to the dll file on both client and server, but it returns an error saying that requested function cannot be found.
the client is connected to the server. then it returns this error.
plz point out what is wrong with my code.
 
Last edited by a moderator:
In server you have registered object address "server.soap", while in client you use object address "Server.Server.soap", these have to be the same
You have to change to Singleton to get the result of first call from second call, else you get a new object each call.
 
Back
Top