HighTechTalks DotNet Forums  

VB.net client cannot instantiate server class?

Dotnet Framework (Remoting) microsoft.public.dotnet.framework.remoting


Discuss VB.net client cannot instantiate server class? in the Dotnet Framework (Remoting) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Lextendo
 
Posts: n/a

Default VB.net client cannot instantiate server class? - 11-20-2007 , 01:48 PM






Hello gurus

My objective: Create a server app which exposes a single class to
other client apps. I do not want to use a config file, so I went for
an Interface approach.

In my server app I created an interface, which is implemented by a
class. This interface is also available in the client app.

== The interface ==
Imports System
Namespace RInputServer
Public Interface IServer

Sub RISReceive(ByVal sMsg As String)
Function ToString() As String

End Interface
End Namespace
====

I want to be able to use the exposed class in the server app ass well,
so instead of "RegisterWellKnownServiceType" i expose the class by
"RemotingServices.Marshal":

== Server code snippet ==
Dim chan As New TcpChannel(1968)
ChannelServices.RegisterChannel(chan, True)
oServer = New RInputServer.clsServer()
oServer.RISMsg = AddressOf ShowNetworkMessage
'RISMsg is the delegate for the implementation of IServer.RISReceive
so i can display the message in my GUI
RemotingServices.Marshal(oServer, "RI_Server",
Type.GetType("RInputServer.IServer"))
====

Now to get the remote class from the server( so I can use it in my
client), I thought this code would do the trick:

== Client code snippet ==
Dim oServer As RInputClient.RInputServer.IServer
oServer =
DirectCast(Activator.GetObject(GetType(RInputClien t.RInputServer.IServer),
"tcp://127.0.0.1:1968/RI_Server"), RInputClient.RInputServer.IServer)
MsgBox(oServer.ToString) 'should display with server implementation as
"Hello: me server"
====

But instead of a msgbox I get an error message:
Cannot load type 'RInputClient.RInputServer.IServer, RInputClient,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.

I'm kind of stuck here....?
Even when I remove then "RInputClient" namespace in the
activator.getobject part, the errormessage remains the same?
What am I doing wrong? Any help would be greatly appreciated.

Regards,
Alex

Reply With Quote
  #2  
Old   
Lextendo
 
Posts: n/a

Default Re: VB.net client cannot instantiate server class? - 11-21-2007 , 04:39 AM






Never mind...

Found the solution: RInputServer.IServer !=
RInputClient.RInputServer.IServer !!!!

I moved the interface to a separate library, so now I have three
projects:
- RIServer (exe)
- RIClient (exe)
- RISContract (dll, contains only IServer)

Both server and client need a reference to Contract.dll for using
Contract.IServer.

so server code changes from:
RemotingServices.Marshal(oServer,
"RI_Server",Type.GetType("RInputServer.IServer "))
to
RemotingServices.Marshal(oServer,
"RI_Server",Type.GetType("RISContract.IServer" ))

Client code from:
Dim oServer As RInputClient.RInputServer.IServer
oServer =
DirectCast(Activator.GetObject(GetType(RInputClien t.RInputServer.IServer),
"tcp://127.0.0.1:1968/RI_Server"), RInputClient.RInputServer.IServer)
to
Dim oServer As RISContract.IServer
oServer = DirectCast(Activator.GetObject(GetType(RISContract .IServer),
"tcp://127.0.0.1:1968/RI_Server"), RISContract.IServer)

Now RISContract.IServer = RISContract.IServer

Though new challenges appear in this 'exercise' the client does
receive the server object


Reply With Quote
  #3  
Old   
Morten Saxov
 
Posts: n/a

Default Re: VB.net client cannot instantiate server class? - 11-21-2007 , 10:21 AM



A god idea, never give your class and namespace the samme name.

I think that Code Analysis will also point this out - but it can help you in
some cases - like this one..

//Morten Saxov

"Lextendo" <lextendo (AT) gmail (DOT) com> wrote

Quote:
Never mind...

Found the solution: RInputServer.IServer !=
RInputClient.RInputServer.IServer !!!!

I moved the interface to a separate library, so now I have three
projects:
- RIServer (exe)
- RIClient (exe)
- RISContract (dll, contains only IServer)

Both server and client need a reference to Contract.dll for using
Contract.IServer.

so server code changes from:
RemotingServices.Marshal(oServer,
"RI_Server",Type.GetType("RInputServer.IServer "))
to
RemotingServices.Marshal(oServer,
"RI_Server",Type.GetType("RISContract.IServer" ))

Client code from:
Dim oServer As RInputClient.RInputServer.IServer
oServer =
DirectCast(Activator.GetObject(GetType(RInputClien t.RInputServer.IServer),
"tcp://127.0.0.1:1968/RI_Server"), RInputClient.RInputServer.IServer)
to
Dim oServer As RISContract.IServer
oServer = DirectCast(Activator.GetObject(GetType(RISContract .IServer),
"tcp://127.0.0.1:1968/RI_Server"), RISContract.IServer)

Now RISContract.IServer = RISContract.IServer

Though new challenges appear in this 'exercise' the client does
receive the server object



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.