views:

13

answers:

2

Is there a way to attach a handler to a soap call?

For example:

I’m calling a row validate for each row in a data grid. This then calls async soap service. On the return of the async is it possible to know which row i called it for without passing some sort of id back and forth?

Thanks

A: 

If you are using the same handler to handle all calls from different row then yes, you have to. Otherwise if you have a handler for each row then you don't.

It is similar to handlers for e.g. button clicks. If you use the same handler for multiple buttons then you need to check the sender object.

I suggest you use an value in HTTP heades to set the ID and work back the caller. In a way, this should not be in your Soap message since server does not need to know about your ID.

Aliostad
+1  A: 

If doing one call for each row. You could pass the row as a userstate. For example using the event-based asynchronous method http://msdn.microsoft.com/en-us/library/ms730059.aspx.

client.AddCompleted += new EventHandler<AddCompletedEventArgs>(AddCallback);
client.AddAsync(value1, value2, row);

And retrieve the row in the callback method

static void AddCallback(object sender, AddCompletedEventArgs e) { var row = e.UserState as RowType; }
RonaldV
+1 that is much better
Aliostad
does this user state get sent to the server? im trying to keep it client side only if possible.
Jonathan D
UserState stays on the client side.
RonaldV