Ken Kolda
7/13/2004 6:42:00 PM
That helps clarify quite a bit. It looks like you''re trying to create a
singleton on the server that will service all the client calls for the
lifetime of the server process. When you use well-known singletons, there
are actually two ways to register them on the server:
1) Using RemotingConfiguration.RegisterWellKnowServerType().
2) Using RemotingServices.Marshal()
You used the Marshal() method but didn''t provide a URI for your singleton
(or at least your pseudocode doesn''t show one). To remedy this, change your
Marshal call to be:
RemotingServices.Marshal(new ServerClass(), "Server.rem", typeof(IServer));
Then, in your client code you do not need to call
RegisterWellKnownClientType, just use Activator.GetObject:
IServer server = (IServer) Activator.GetObject(typeof(IServer),
"tcp://yourserver:portnum/Server.rem");
(You obviously need to substitute the name of your server and the
appropriate port number in the string above). That''s it -- no need to call
any Register methods.
Ken
"Ivo Bronsveld" <nospam-bronsveld@bts.net> wrote in message
news:eFMFcXQaEHA.972@TK2MSFTNGP12.phx.gbl...
> Ken,
>
> I''ll try to clarify it for you by using some pseudo code. Hope that
helps...
>
>
> "Ken Kolda" <ken.kolda@elliemae-nospamplease.com> schreef in bericht
> news:uJ0N6GPaEHA.644@tk2msftngp13.phx.gbl...
> > There are some confusing things in what you''ve written that need some
> > clarification. See comments inline below...
> >
> > What do you mean by "creating an instance of the interface"? You cannot
> > create instances of interfaces. Also, are you say that the "interface is
> > registered as a WellKnownClientTypeEntry". Are you saying you created a
> > WKCTE instance with an interface type and then call
> > RegisterWellKnownClientType() on it? I''ve never done that before and I''m
> > surprised it didn''t complain at runtime since I''m not sure how that
could
> be
> > useful. Calling the RegisterWellKnownClientType() method allows you to
use
> > the "new" key word instead of the Activator object to create remote
> objects,
> > but since you can''t "new" an interface, I don''t know what value that
would
> > have.
> >
>
> I''m aware of the fact I can''t create an instance of the interface. What I
> meant was something like this:
>
> Server.Interfaces.DLL
> --------------------------------------------
> public interface IServer
> {
> bool Validate(string Name, string Password);
> }
>
> Server.Implementation.EXE
> --------------------------------------------
> public class ServerClass : IServer
> {
> public bool Validate(string Name, string Password)
> {
> }
> }
>
> public ConsoleClass
> {
> Main
> {
> RemotingServices.Marshal(new ServerClass());
> }
> }
>
> What I meant was, I register the implementation of the interface as a
> server.
>
> In the client I do something like this:
>
> RemotingServices.RegisterWellKnownClientTypeEntry(typeof(IServer)) etc..
> IServer server = Activator.GetObject(typeof(IServer));
>
> bool isvalidated = server.Validate(name, password);
>
> I use the interface to prevent my clients (or in this case my components)
> from using / seeing
> the implementation (class) of the server. Microsoft gives this as a
possible
> solution for a similar scenario...
>
> >
> > Activate.CreateInstance() would be used to create a new client-activated
> > object, but you previously indicated you were registering your remote
> > objects as "WellKnown" (i.e. server-activated). Which are you trying to
> > achieve?
> >
>
> I''m basically trying to get a way to communicate with my server without
> having to include my
> complete implementation as a referenced dll. This is possible by using
> interfaces, I''ve done this before.
> The interface is not really the problem. The problem occurs when using the
> component in ASP.NET...
> What happens is that my component gets re-created after a postback. When
my
> component is created,
> it registers the ClientType based on a configuration URL. This cannot be
> done twice... Enter my problem.
>
> So I tried another scenario, without registering my interface as a
> WellKnownClientTypeEntry. That way
> I should be able to retreive an instance of the server without any
> registration. The problem however,
> is that I use an interface as server declaration.
> When I use the Activator.CreateInstance() method, which makes it possible
to
> work with remoting objects
> without registering them as client / server activated objects, an
exception
> occurs, because I used an interface on the
> server. My interface doesn''t implement MarshalByRefObject, because an
> interface can''t inherit from a class...
>
> > Assuming you''re looking for a SAO, what you likely need to do is to use
> > Activator.GetObject() to retrieve the object from the server. Cast the
> > return value to your desired interface type and call your methods as
> usual.
> > No calls are needed to register the type on the client side.
> >
> > Ken
>
> As far as I know the Activator.GetObject required wellknow types to work
> with:
> From MSDN:
>
> Activator.GetObject Method (Type, String)
> Creates a proxy for the well-known object indicated by the specified type
> and URL.
>
> I will give it a try when I''m back at work tomorrow. I hope I clarified it
a
> bit more. It was the end of my workday,
> so it''s not that strange that things weren''t as obvious as I hoped they
> would be ;-)
>
> Thanx,
>
> Ivo
>
>