C# async soap object handle
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开发者_JAVA百科 to know which row i called it for without passing some sort of id back and forth?
Thanks
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; }
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.
精彩评论