[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

microsoft.public.dotnet.framework.remoting

Remote event subscription not working.

Brian Vallelunga

8/21/2004 2:44:00 AM

I hope someone can help me. I'm trying to implement a remote object and
subscribe to an event on it. I'm using an event wrapper as suggested in Ingo
Rammer's book so that I can use interfaces with remoting. My problem is that
my server object's event never gets subscribed to successfully. The wrapper
seems to work fine, but when I have the event fire via another remote
method, no listeners are subscribed.

I have a suspicion what the problem is. When I first tried to run the code
given in the book, I received a security error. The error was the change to
the serialization made in the 1.1 version of the framework. On my remoting
server, I made the changes to the configuration file to specify the
TypeFilterLevel to full. I no longer receive the error. However, I'm unsure
if I'm supposed to set this setting on the client as well. I was using
config files on the server, but code for the remoting client. The code I was
using for the client was very simple:

TcpClientChannel tcpChannel = new TcpClientChannel();
ChannelServices.RegisterChannel(tcpChannel);

IRemoteObject obj = (IRemoteObject )Activator.GetObject(
typeof(IRemoteObject ), "tcp://localhost:8085/IRemoteObject .rem" );


Do I need to specify the TypeFilterLevel on the client's end? If so, how do
I do this in code? I've seen some examples that use TcpChannel instead of
TcpClientChannel and I tried to implement it that way, but when I did, I get
an error stating that the channel is already registered on the computer. I'm
not quite sure what to do.

Thanks for any help.

Brian


4 Answers

Sam Santiago

8/21/2004 8:02:00 AM

0

Check out this remoting event example. I think you need to use delegates:

Chat Client
http://support.microsoft.com/default.aspx?scid=kb;en...

Ingo Rammer's website has an example of the security fix. Watch out for
case, it does matter:
http://www.thinktecture.com/Resources/RemotingFAQ/Change...

To register a channel programmatically check out the example at this link:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemruntimeremotingchannelschannelservicesclassregisterchanne...

You can create channels with names. Use the constructor that allows you to
pass properties for the channel. The default name for a TCP channel is
'tcp' and for an HTTP channel is 'http' and you can only have one channel
with the same name within each AppDomain. So it sounds like you are trying
to create two channels without specifying a name. You could have one
created via the configuration file without a name and then trying to create
another programmatically and get this error.

Thanks,

Sam

--
_______________________________
Sam Santiago
ssantiago@n0spam-SoftiTechture.com
http://www.SoftiTe...
_______________________________
"Brian Vallelunga" <bgvallelunga@starpower.net> wrote in message
news:OBkOFjyhEHA.644@tk2msftngp13.phx.gbl...
> I hope someone can help me. I'm trying to implement a remote object and
> subscribe to an event on it. I'm using an event wrapper as suggested in
Ingo
> Rammer's book so that I can use interfaces with remoting. My problem is
that
> my server object's event never gets subscribed to successfully. The
wrapper
> seems to work fine, but when I have the event fire via another remote
> method, no listeners are subscribed.
>
> I have a suspicion what the problem is. When I first tried to run the code
> given in the book, I received a security error. The error was the change
to
> the serialization made in the 1.1 version of the framework. On my remoting
> server, I made the changes to the configuration file to specify the
> TypeFilterLevel to full. I no longer receive the error. However, I'm
unsure
> if I'm supposed to set this setting on the client as well. I was using
> config files on the server, but code for the remoting client. The code I
was
> using for the client was very simple:
>
> TcpClientChannel tcpChannel = new TcpClientChannel();
> ChannelServices.RegisterChannel(tcpChannel);
>
> IRemoteObject obj = (IRemoteObject )Activator.GetObject(
> typeof(IRemoteObject ), "tcp://localhost:8085/IRemoteObject .rem" );
>
>
> Do I need to specify the TypeFilterLevel on the client's end? If so, how
do
> I do this in code? I've seen some examples that use TcpChannel instead of
> TcpClientChannel and I tried to implement it that way, but when I did, I
get
> an error stating that the channel is already registered on the computer.
I'm
> not quite sure what to do.
>
> Thanks for any help.
>
> Brian
>
>


Brian Vallelunga

8/21/2004 1:19:00 PM

0

"Sam Santiago" <ssantiago@n0spam-SoftiTechture.com> wrote in message
news:evqRdU1hEHA.2624@TK2MSFTNGP12.phx.gbl...
> Check out this remoting event example. I think you need to use delegates:
>
> Chat Client
> http://support.microsoft.com/default.aspx?scid=kb;en...

I am using delegates for this process along with a wrapper to provide a full
implementation for both client and server. This event wrapper is identical
to the one in Ingo Rammer's book on page 191. It basically replaces the need
for the abstract class definined in the article above. The event wrapper I
have is defined as:

public class TraceEventWrapper : System.MarshalByRefObject
{
public event MessageArrivedHandler MessageArrivedLocally;

public void LocallyHandleMessageArrived ( string message )
{
// Forward to client
MessageArrivedLocally( message );
}

public override object InitializeLifetimeService()
{
// Object lives "forever"
return null;
}
}

Basically, the client subscribes to the MessageArrivedLocally event, while
my remoting singleton's event has the wrapper's LocallyHandleMessageArrived
method as its handler. The process goes:

Server Event => EventWrapper.LocallyHandleMessageArrived =>
EventWrapper.MessageArrivedLocally => Client's handler for
EventWrapper.MessageArrivedLocally

The problem lies with the server's event not having any handlers subscribed
to it, after clearly subscribing. In code:

// Get a reference to the singleton object on the server
traceService = (ITraceService)Activator.GetObject( typeof(ITraceService),
"tcp://localhost:8085/TraceService.rem" );

// Create a wrapper
TraceEventWrapper eventWrapper = new TraceEventWrapper();

// Subscribe to the wrapper's event
eventWrapper.MessageArrivedLocally += new MessageArrivedHandler(
HandleMessage );

// Subscribe to the trace service's event, pointing it to the event
wrapper's handler
traceService.MessageArrived += new MessageArrivedHandler(
eventWrapper.LocallyHandleMessageArrived );

The last line is where I clearly subscribe to the event, but it doesn't seem
to go through. I think it is because of the new security permissions, but I
am unable to confirm this hypothesis.

> Ingo Rammer's website has an example of the security fix. Watch out for
> case, it does matter:
> http://www.thinktecture.com/Resources/RemotingFAQ/Change...

This code is not clear. Is this for the client, server, or both? On the
server, I am using a configuration file which includes:

<channels>
<channel ref="tcp" port="8085">
<serverProviders>
<formatter ref="binary" typeFilterLevel="Full" />
</serverProviders>
</channel>
</channels>

What do I do on the client side? I'm not using a configuration file and I
currently have:

// Register TcpChannel
TcpClientChannel remotingChannel = new TcpClientChannel( );
ChannelServices.RegisterChannel( remotingChannel );
// Get a reference to the singleton object on the server
traceService = (ITraceService)Activator.GetObject( typeof(ITraceService),
"tcp://localhost:8085/TraceService.rem" );

If I change this code to look like what Ingo suggests on his site (but using
TcpChannel), I receive an error stating the channel has already been
registered. By what, I'm not sure. It seems as though I want just a client
channel, but this is where I am most confused and where I think the error
comes in.

Thanks for the help, and I hope this makes things clearer.

Brian


Sam Santiago

8/22/2004 12:11:00 AM

0

I'm not sure about the events. You might want to try it both ways to to see
if you can get it to work - the way like the chat client example and like
you're doing it know.

Here's an example of configuring channels programmatically:

Client Side:

Dim clientProv As BinaryClientFormatterSinkProvider
Dim serverProv As BinaryServerFormatterSinkProvider = New
BinaryServerFormatterSinkProvider
serverProv.TypeFilterLevel =
System.Runtime.Serialization.Formatters.TypeFilterLevel.Full
clientProv = New BinaryClientFormatterSinkProvider
Dim props As IDictionary = New Hashtable
props("port") = 0
Dim chan As HttpChannel = New HttpChannel(props, clientProv, serverProv)
ChannelServices.RegisterChannel(chan)

Server Side:

Dim clientProv As BinaryClientFormatterSinkProvider
Dim serverProv As BinaryServerFormatterSinkProvider = New
BinaryServerFormatterSinkProviderserverProv.TypeFilterLevel =
System.Runtime.Serialization.Formatters.TypeFilterLevel.Full
clientProv = New BinaryClientFormatterSinkProvider
Dim props As IDictionary = New Hashtable
props("port") = 8085
Dim chan As HttpChannel = New HttpChannel(props, clientProv, serverProv)
ChannelServices.RegisterChannel(chan)

Thanks,
Sam

--
_______________________________
Sam Santiago
ssantiago@n0spam-SoftiTechture.com
http://www.SoftiTe...
_______________________________
"Brian Vallelunga" <bgvallelunga@starpower.net> wrote in message
news:eHpz9F4hEHA.2916@TK2MSFTNGP12.phx.gbl...
> "Sam Santiago" <ssantiago@n0spam-SoftiTechture.com> wrote in message
> news:evqRdU1hEHA.2624@TK2MSFTNGP12.phx.gbl...
> > Check out this remoting event example. I think you need to use
delegates:
> >
> > Chat Client
> > http://support.microsoft.com/default.aspx?scid=kb;en...
>
> I am using delegates for this process along with a wrapper to provide a
full
> implementation for both client and server. This event wrapper is identical
> to the one in Ingo Rammer's book on page 191. It basically replaces the
need
> for the abstract class definined in the article above. The event wrapper I
> have is defined as:
>
> public class TraceEventWrapper : System.MarshalByRefObject
> {
> public event MessageArrivedHandler MessageArrivedLocally;
>
> public void LocallyHandleMessageArrived ( string message )
> {
> // Forward to client
> MessageArrivedLocally( message );
> }
>
> public override object InitializeLifetimeService()
> {
> // Object lives "forever"
> return null;
> }
> }
>
> Basically, the client subscribes to the MessageArrivedLocally event, while
> my remoting singleton's event has the wrapper's
LocallyHandleMessageArrived
> method as its handler. The process goes:
>
> Server Event => EventWrapper.LocallyHandleMessageArrived =>
> EventWrapper.MessageArrivedLocally => Client's handler for
> EventWrapper.MessageArrivedLocally
>
> The problem lies with the server's event not having any handlers
subscribed
> to it, after clearly subscribing. In code:
>
> // Get a reference to the singleton object on the server
> traceService = (ITraceService)Activator.GetObject( typeof(ITraceService),
> "tcp://localhost:8085/TraceService.rem" );
>
> // Create a wrapper
> TraceEventWrapper eventWrapper = new TraceEventWrapper();
>
> // Subscribe to the wrapper's event
> eventWrapper.MessageArrivedLocally += new MessageArrivedHandler(
> HandleMessage );
>
> // Subscribe to the trace service's event, pointing it to the event
> wrapper's handler
> traceService.MessageArrived += new MessageArrivedHandler(
> eventWrapper.LocallyHandleMessageArrived );
>
> The last line is where I clearly subscribe to the event, but it doesn't
seem
> to go through. I think it is because of the new security permissions, but
I
> am unable to confirm this hypothesis.
>
> > Ingo Rammer's website has an example of the security fix. Watch out for
> > case, it does matter:
> > http://www.thinktecture.com/Resources/RemotingFAQ/Change...
>
> This code is not clear. Is this for the client, server, or both? On the
> server, I am using a configuration file which includes:
>
> <channels>
> <channel ref="tcp" port="8085">
> <serverProviders>
> <formatter ref="binary" typeFilterLevel="Full" />
> </serverProviders>
> </channel>
> </channels>
>
> What do I do on the client side? I'm not using a configuration file and I
> currently have:
>
> // Register TcpChannel
> TcpClientChannel remotingChannel = new TcpClientChannel( );
> ChannelServices.RegisterChannel( remotingChannel );
> // Get a reference to the singleton object on the server
> traceService = (ITraceService)Activator.GetObject( typeof(ITraceService),
> "tcp://localhost:8085/TraceService.rem" );
>
> If I change this code to look like what Ingo suggests on his site (but
using
> TcpChannel), I receive an error stating the channel has already been
> registered. By what, I'm not sure. It seems as though I want just a client
> channel, but this is where I am most confused and where I think the error
> comes in.
>
> Thanks for the help, and I hope this makes things clearer.
>
> Brian
>
>


Brian Vallelunga

8/22/2004 12:58:00 PM

0

Sam Santiago wrote:
> I'm not sure about the events. You might want to try it both ways to to see
> if you can get it to work - the way like the chat client example and like
> you're doing it know.

Thanks for the help. I figured out the events problem, as it was quite
stupid. I accidentally had my configuration file set the remoting object
to SingleCall instead of Singleton. Thus, after the event was
subscribed, the object was immediately destroyed. Duh...

I also figured out the problem with the client side code for configuring
a channel. My problem was that I was not using port 0. Doing this made
everything work.

Thanks for the help.

Brian