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...
[quoted text, click to view] > 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...
[quoted text, click to view] >
> 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...
[quoted text, click to view] > 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