Remoting and objects design problem

L

Lloyd Sheen

Sorry about the length of this post but I felt it was better to show all the
details in order to get some resolution.


I have the following senario:
- a service which hosts objects for remoting they are defined as shown
below

Dim chan As TcpChannel
chan = New TcpChannel(52001)
ChannelServices.RegisterChannel(chan)


RemotingConfiguration.RegisterWellKnownServiceType(Type.GetType("ChatLibrary
..ChatManager,ChatLibrary"), "ChatServer", WellKnownObjectMode.Singleton)

'RemotingConfiguration.RegisterWellKnownServiceType(Type.GetType("ChatLibrar
y.ChatUser,ChatLibrary"), "ChatServer", WellKnownObjectMode.Singleton)

- note that the second register is commented out since only one object can
be defined it seems.

- ok I will make that object a factory so that it can provide objects with
functions to return those objects

- now to attempt to use the objects


Try
ChannelServices.RegisterChannel(chan)
Catch ex As Exception
Exit Sub
End Try


Try
chatObject =
CType(Activator.GetObject(Type.GetType("ChatLibrary.ChatManager,
ChatLibrary"), "tcp://localhost:52001/ChatServer"), ChatLibrary.ChatManager)
If chatObject Is Nothing Then
MsgBox("Service does not seem to up and running")

This does not happen unless I forget to start the service.

Else
Try
Dim poUser As ChatUser
Dim pocm As ChatMessage
pocm = chatObject.GetMessage
MsgBox(pocm.MsgSender)

This method show the dummy string I put into the function


poUser = chatObject.GetNewUser

Now debugging shows a proxy object for poUser

MsgBox(CStr(poUser.IsLoggedOn))

The above line shows the dummy value I have provided.


chatObject.Logon(poUser)

This is the line that gives the error. It indicates an internal error in
the service. I guess the question is can remoting serve more than one
object. That seems to be true since all the objects created seem to exist.
The problem is in using the object as a parameter.

Catch ex As Exception
MsgBox(ex.message)
End Try
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try


The following is the definition of the "manager/factory" object and the
function that returns the ChatUser object.

Public Class ChatManager
Inherits MarshalByRefObject

Public Function GetNewUser() As ChatUser
Dim poUser As New ChatUser
Return poUser
End Function


The following is the definition of the object that I want to use as a
paramter.

Public Class ChatUser
Inherits MarshalByRefObject

Property IsLoggedOn() As Boolean
Get
Return mbLoggedOn
End Get
Set(ByVal Value As Boolean)
mbLoggedOn = Value
End Set
End Property


Any ideas?
Lloyd Sheen
 
D

Dmitriy Lapshin [C# / .NET MVP]

The ChatUser object returned is a proxy, not the actual object. Now you pass
the reference back to the remoting server:
chatObject.Logon(poUser)

And this is the most possible cause of the error.
I'd make the Logon a method of the ChatUser class instead to avoid passing
back the reference to an object residing on the server side.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top