[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Ivo Bronsveld

7/13/2004 3:09:00 PM

All,

I got some tricky problems with .NET remoting. I created a generic remoting
server. This server implements an interface. By doing it this way I hide the
server implementation in my client applications. I also created a (client)
component which communicates with the server. It connects to the remoting
server by creating an instance of the interface. The interface is registered
as a WellKnownClientTypeEntry.

So far so good.When I use this component in my windows forms applications
everything kind of works, because there's no need to re-create an instance
of the component. Therefore it doesn't try to re-register the
WellKnownClientTypeEntry. When used in ASP.NET the problems start... The
Attempt to redirect activation of type 'bla' exception occurs when run for
the second time.

I tried working around the problem by not registering it as a
WellKnownClientTypeEntry, but by making it available using
Activator.CreateInstance()...
However, it requires my server (interface) to be inherited from
MarshalByRefObject. But, this is not possible with an interface...

The server url must be dynamic, or at least configurable by using
configuration files or something...

Can anybody help me? I'm really getting depressed from these problems ;-)
Any info appreciated...

Kind Regards,

Ivo Bronsveld
(please remove the nospam from my e-mailaddress when replying directly to
me)


5 Answers

Ken Kolda

7/13/2004 3:54:00 PM

0

There are some confusing things in what you''ve written that need some
clarification. See comments inline below...


"Ivo Bronsveld" <nospam-bronsveld@bts.net> wrote in message
news:u%23auetOaEHA.2812@tk2msftngp13.phx.gbl...
> All,
>
> I got some tricky problems with .NET remoting. I created a generic
remoting
> server. This server implements an interface. By doing it this way I hide
the
> server implementation in my client applications. I also created a (client)
> component which communicates with the server. It connects to the remoting
> server by creating an instance of the interface. The interface is
registered
> as a WellKnownClientTypeEntry.

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.


>
> So far so good.When I use this component in my windows forms applications
> everything kind of works, because there''s no need to re-create an instance
> of the component. Therefore it doesn''t try to re-register the
> WellKnownClientTypeEntry. When used in ASP.NET the problems start... The
> Attempt to redirect activation of type ''bla'' exception occurs when run for
> the second time.
>
> I tried working around the problem by not registering it as a
> WellKnownClientTypeEntry, but by making it available using
> Activator.CreateInstance()...
> However, it requires my server (interface) to be inherited from
> MarshalByRefObject. But, this is not possible with an interface...

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?

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


Ivo Bronsveld

7/13/2004 6:19:00 PM

0

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


Ken Kolda

7/13/2004 6:42:00 PM

0

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
>
>


Ivo Bronsveld

7/14/2004 9:02:00 AM

0

Ken,

Thanx... I misread the MSDN documentation. I thought the well-known object
meant you have to register them as a wellknown type, but it doesn''t...
That helps a lot...

Thanx again...

Ivo Bronsveld


Allen Anderson

7/15/2004 9:22:00 PM

0

You can use an abstract class if you want it to inherit from MBR
instead of using an interface. Also, you shouldn''t have to keep
registering the welknownclienttype.

Cheers,
Allen Anderson
http://www.glacialcomp...
mailto: allen@put my website base here.com

On Tue, 13 Jul 2004 17:09:07 +0200, "Ivo Bronsveld"
<nospam-bronsveld@bts.net> wrote:

>All,
>
>I got some tricky problems with .NET remoting. I created a generic remoting
>server. This server implements an interface. By doing it this way I hide the
>server implementation in my client applications. I also created a (client)
>component which communicates with the server. It connects to the remoting
>server by creating an instance of the interface. The interface is registered
>as a WellKnownClientTypeEntry.
>
>So far so good.When I use this component in my windows forms applications
>everything kind of works, because there''s no need to re-create an instance
>of the component. Therefore it doesn''t try to re-register the
>WellKnownClientTypeEntry. When used in ASP.NET the problems start... The
>Attempt to redirect activation of type ''bla'' exception occurs when run for
>the second time.
>
>I tried working around the problem by not registering it as a
>WellKnownClientTypeEntry, but by making it available using
>Activator.CreateInstance()...
>However, it requires my server (interface) to be inherited from
>MarshalByRefObject. But, this is not possible with an interface...
>
>The server url must be dynamic, or at least configurable by using
>configuration files or something...
>
>Can anybody help me? I''m really getting depressed from these problems ;-)
>Any info appreciated...
>
>Kind Regards,
>
>Ivo Bronsveld
>(please remove the nospam from my e-mailaddress when replying directly to
>me)
>