WCF client Multi Event Problem

my Problem are the events from the WCF client. I hand the client object to some classes. And in this classes i created the events. If i created in different classes the same event it's fires many times. I want that only the event fires in the class where i call the WCF.

How can i solve the Problem? Only Remove each event after complete?

Sry for my english ;)

Thanks....

Answers


Hi I don't understand your question quite well, but I'll try to answer the way I did. When you reference a WCF service, as you know proxy classes will be generated in client project. This proxy classes share the same data member's Interface which is on the server-side, but not the behavior. So for instance, all properties will be accessible from the client, but not events, methods and so on. Maybe you can write what you are trying to accomplish and we may help?

Update


Ok, now I think I understand. Well that's a solution to remove each event which shouldn't fire before you execute AddNumber method. Another solution is to keep track of calling classes. for example

public static ArrayList eventObjects = new ArrayList(); //Declare a global array list which will be accessible from all classes

eventObjects.Add(this); //Before calling AddNumber method
_client.AddNumber += new EventHandler<AddNumberCompletedEventArgs>(_client_AddNumberCompleted);
void _client_AddNumberCompleted(object sender, AddNumberCompletedEventArgs e)
{
     if(ar.Contains(this))
     {
         //Do what you want to do here. Other classes will receive this event too, but they will not react.
         eventObjects.Remove(this);
     }
}

However I must warn you that this is not a best approach. I can't suggest you a better way because I don't know what you are trying to accomplish.


okay sorry.

I added the WCF to the Service References in the client project. Then i created a instance from the Webservice Client:

private WServiceClient _client = new WService.WServiceClient();

I hand this object to several classes. In this classes i create the complete events from some Methodes from the WCF (asyc calls). Like this:

_client.AddNumber += new EventHandler<AddNumberCompletedEventArgs>(_client_AddNumberCompleted);

        void _client_AddNumberCompleted(object sender, AddNumberCompletedEventArgs e)
        {

        }

The problem is that i use some methods multiple in different classes, i create more than one complete event. If the Complete Event fires, all event fires in all classes. I want that it only the event fires who was in the class where the call was made.

I hope you understand my description.

Update:

i solve my Problem with remove the event from the eventhandler in the Complete Event.


Need Your Help

QImage from unsigned char buffer (jpg format)

c++ image qt jpeg

I have buffer of type unsigned char* which I fill with JPG image. I want to use this buffer to draw the image to my application screen in a QLabel.

Exported pdf in iReport not displaying correct font

jasper-reports

I am trying to display a simple kannada text in iReport. The font I am using is Tunga.ttf and it gets embedded as subset in exported pdf but the words are not displayed correctly.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.