[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

microsoft.public.dotnet.framework.remoting

Issue with .net remoting events

DotNetJunkies User

6/30/2004 3:47:00 AM

Hi
For some reason, the event handler is not getting subscribed to the event.

Here's the code
=====================================
>>> Shared Assembly
using System;

namespace SharedAssemblyCarProject
{
public class EventShim: MarshalByRefObject
{
protected NewCarFoundEventHandler TargetHandlers;
public EventShim(NewCarFoundEventHandler Target)
{
TargetHandlers += Target;
}
public void Execute(string car)
{
TargetHandlers(car);
}
}

public delegate void NewCarFoundEventHandler(string car);
public interface ICarAgency
{
string[] GetCars();
string ReserverCar(string car);
event NewCarFoundEventHandler NewCarFoundEvent;
}
}
=====================================
>>>> Server code
using System;
using SharedAssemblyCarProject;

namespace RemoteServer
{
public class AvisCarAgency : MarshalByRefObject, SharedAssemblyCarProject.ICarAgency
{
public AvisCarAgency()
{
//
// TODO: Add constructor logic here
//
}

public string[] GetCars()
{
if (NewCarFoundEvent!=null)
NewCarFoundEvent("Honda");
return new string[] {"Honda", "Toyota", "Civic", "Merc", "BMW", "NISSAN" };
}

public string ReserverCar(string car)
{
return "Reserverd";
}

public event NewCarFoundEventHandler NewCarFoundEvent;
}
}
======================================
>> Client
EventShim shim = new EventShim(new NewCarFoundEventHandler(AvisBoston_NewCarFoundEvent));

AvisBoston.NewCarFoundEvent += new NewCarFoundEventHandler(shim.Execute);

MessageBox.Show("Number: " + AvisBoston.GetCars().Length);
======================================

The method AvisBoston_NewCarFoundEvent is present in the client class. Also, I've added the typeFilterLevel attribute to get rid of the serialization exception in .net 1.1.

My problem is that although I think Im adding the handler in
AvisBoston.NewCarFoundEvent += new .....
statement, when I call the GetCars() method, it test for null of NewCarFoundEvent and returns true.

Any suggestions would be highly appreciated.


---
Posted using Wimdows.net NntpNews Component -

Post Made from http://www.DotNetJunkies.com/... Our newsgroup engine supports Post Alerts, Ratings, and Searching.
2 Answers

Sunny

6/30/2004 3:17:00 PM

0

Hi,

I can not see at first look any problem here. Can you send stripped
sample?

Sunny


In article <#dADqTlXEHA.1000@TK2MSFTNGP12.phx.gbl>, User@-NOSPAM-
DotNetJunkies.com says...
> Hi
> For some reason, the event handler is not getting subscribed to the event.
>
> Here''s the code
> =====================================
> >>> Shared Assembly
> using System;
>
> namespace SharedAssemblyCarProject
> {
> public class EventShim: MarshalByRefObject
> {
> protected NewCarFoundEventHandler TargetHandlers;
> public EventShim(NewCarFoundEventHandler Target)
> {
> TargetHandlers += Target;
> }
> public void Execute(string car)
> {
> TargetHandlers(car);
> }
> }
>
> public delegate void NewCarFoundEventHandler(string car);
> public interface ICarAgency
> {
> string[] GetCars();
> string ReserverCar(string car);
> event NewCarFoundEventHandler NewCarFoundEvent;
> }
> }
> =====================================
> >>>> Server code
> using System;
> using SharedAssemblyCarProject;
>
> namespace RemoteServer
> {
> public class AvisCarAgency : MarshalByRefObject, SharedAssemblyCarProject.ICarAgency
> {
> public AvisCarAgency()
> {
> //
> // TODO: Add constructor logic here
> //
> }
>
> public string[] GetCars()
> {
> if (NewCarFoundEvent!=null)
> NewCarFoundEvent("Honda");
> return new string[] {"Honda", "Toyota", "Civic", "Merc", "BMW", "NISSAN" };
> }
>
> public string ReserverCar(string car)
> {
> return "Reserverd";
> }
>
> public event NewCarFoundEventHandler NewCarFoundEvent;
> }
> }
> ======================================
> >> Client
> EventShim shim = new EventShim(new NewCarFoundEventHandler(AvisBoston_NewCarFoundEvent));
>
> AvisBoston.NewCarFoundEvent += new NewCarFoundEventHandler(shim.Execute);
>
> MessageBox.Show("Number: " + AvisBoston.GetCars().Length);
> ======================================
>
> The method AvisBoston_NewCarFoundEvent is present in the client class. Also, I''ve added the typeFilterLevel attribute to get rid of the serialization exception in .net 1.1.
>
> My problem is that although I think Im adding the handler in
> AvisBoston.NewCarFoundEvent += new .....
> statement, when I call the GetCars() method, it test for null of NewCarFoundEvent and returns true.
>
> Any suggestions would be highly appreciated.
>
>
> ---
> Posted using Wimdows.net NntpNews Component -
>
> Post Made from http://www.DotNetJunkies.com/... Our newsgroup engine supports Post Alerts, Ratings, and Searching.
>

Ken Kolda

6/30/2004 3:33:00 PM

0

Check to make sure you''re not remoting your AvisCarAgency instance as a
SingleCall instead of a Singleton -- that''s the most likely source of your
problems.

Ken


"DotNetJunkies User" <User@-NOSPAM-DotNetJunkies.com> wrote in message
news:%23dADqTlXEHA.1000@TK2MSFTNGP12.phx.gbl...
> Hi
> For some reason, the event handler is not getting subscribed to the event.
>
> Here''s the code
> =====================================
> >>> Shared Assembly
> using System;
>
> namespace SharedAssemblyCarProject
> {
> public class EventShim: MarshalByRefObject
> {
> protected NewCarFoundEventHandler TargetHandlers;
> public EventShim(NewCarFoundEventHandler Target)
> {
> TargetHandlers += Target;
> }
> public void Execute(string car)
> {
> TargetHandlers(car);
> }
> }
>
> public delegate void NewCarFoundEventHandler(string car);
> public interface ICarAgency
> {
> string[] GetCars();
> string ReserverCar(string car);
> event NewCarFoundEventHandler NewCarFoundEvent;
> }
> }
> =====================================
> >>>> Server code
> using System;
> using SharedAssemblyCarProject;
>
> namespace RemoteServer
> {
> public class AvisCarAgency : MarshalByRefObject,
SharedAssemblyCarProject.ICarAgency
> {
> public AvisCarAgency()
> {
> //
> // TODO: Add constructor logic here
> //
> }
>
> public string[] GetCars()
> {
> if (NewCarFoundEvent!=null)
> NewCarFoundEvent("Honda");
> return new string[] {"Honda", "Toyota", "Civic", "Merc", "BMW",
"NISSAN" };
> }
>
> public string ReserverCar(string car)
> {
> return "Reserverd";
> }
>
> public event NewCarFoundEventHandler NewCarFoundEvent;
> }
> }
> ======================================
> >> Client
> EventShim shim = new EventShim(new
NewCarFoundEventHandler(AvisBoston_NewCarFoundEvent));
>
> AvisBoston.NewCarFoundEvent += new NewCarFoundEventHandler(shim.Execute);
>
> MessageBox.Show("Number: " + AvisBoston.GetCars().Length);
> ======================================
>
> The method AvisBoston_NewCarFoundEvent is present in the client class.
Also, I''ve added the typeFilterLevel attribute to get rid of the
serialization exception in .net 1.1.
>
> My problem is that although I think Im adding the handler in
> AvisBoston.NewCarFoundEvent += new .....
> statement, when I call the GetCars() method, it test for null of
NewCarFoundEvent and returns true.
>
> Any suggestions would be highly appreciated.
>
>
> ---
> Posted using Wimdows.net NntpNews Component -
>
> Post Made from http://www.DotNetJunkies.com/... Our newsgroup
engine supports Post Alerts, Ratings, and Searching.