Remoting newbie help request -
11-18-2007
, 02:54 PM
Hi,
The scenario is this: I have multiple client applications (VB.Net 2.0) that
need to exchange data via a remote server e.g. Client A sends data to the
remote server and Client B is able to read from the server the data sent by
Client A.
Additionally, I am using the Observer pattern so that the server can
maintain an internal list of all connected clients. The Observer pattern
interfaces are compiled into a separate dll referenced by each client and the
server.
In the Form_Load event in each client, I create the communication channel:
' Create and register channel
Dim channel As HttpChannel = New HttpChannel
ChannelServices.RegisterChannel(channel, False)
The client app has a button to connect to the server. In the button click
event, I connect to the server as follows:
' Check first to see if there is an existing instance running
m_server = CType(Activator.GetObject(GetType(IConnection),
"http://localhost:8080/DataService.soap"), IConnection)
If (m_server Is Nothing) Then
m_server = CType(Activator.CreateInstance(GetType(IConnection ),
New Object()), IConnection)
End If
m_server.Connect(Me)
Note: IConnection is my alias for the ISubject interface in the Observer
pattern and Connect() is an alias for the ISubject.Attach() method.
My remote server is a Windows Forms app (so that it contains the remotable
server object and acts as the host as well) that contains a single form and a
DataService class, the definition of which is as follows:
<Serializable()> _
Public Class DataService
Inherits MarshalByRefObject
Implements IConnection
Private m_clients As List(Of IClient)
Public Sub New()
If (m_clients Is Nothing) Then
m_clients = New List(Of IClient)
End If
End Sub
Public Sub Connect(ByVal client As IClient) Implements IConnection.Connect
m_clients.Add(client)
End Sub
Public Sub Disconnect(ByVal client As IClient) Implements
IConnection.Disconnect
m_clients.Remove(client)
End Sub
End Class
When the server starts, the Form_Load event creates the remoting channel as
follows:
Dim channel As HttpChannel = New HttpChannel(8080)
ChannelServices.RegisterChannel(channel, False)
RemotingConfiguration.RegisterWellKnownServiceType (GetType(DataService),
"DataService.soap", WellKnownObjectMode.Singleton)
My problem is that when the client calls the Connect() method, I get a
SerializationException : Because of security restrictions, the type
System.Runtime.Remoting.ObjRef cannot be accessed.
What have I done wrong? I have my firewall settings and port 8080 is open.
Regards,
James |