Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Remoting / June 2004

Tip: Looking for answers? Try searching our database.

Issue with .net remoting events

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
DotNetJunkies User - 30 Jun 2004 04:47 GMT
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.

---
Sunny - 30 Jun 2004 16:16 GMT
Hi,

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

Sunny

> Hi
> For some reason, the event handler is not getting subscribed to the event.
[quoted text clipped - 76 lines]
>
> ---
Ken Kolda - 30 Jun 2004 16:32 GMT
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

> Hi
> For some reason, the event handler is not getting subscribed to the event.
[quoted text clipped - 68 lines]
>
> 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 .....
[quoted text clipped - 5 lines]
>
>  Our newsgroup
engine supports Post Alerts, Ratings, and Searching.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.