2

Here is the scenario.

I have a WinForm application(C#, .NET 3.5) that follows the Asynchronous Event-Based design pattern.

The main control(MainResultControl) creates multiple instances of child controls(ResultControl) as the user requests. Each child control has unique set of parameters that users selects.

Each child control then calls WCF service asynchronously:

WebServiceClient.GetResultsAsync(Parameters param)

Each child control also signs up for GetResultsCompleted event of the Web Service

WebServiceClient.GetResultsCompleted += _service_GetResultsCompleted()

Here is the problem that we are facing. Users complain that sometimes ResultControl displays the unexpected set of data - unrelated to what they requested.

Is it possible that one instance of control receives the results that the other instance requested when it handles GetResultsCompleted event raised in the web service?

Thank you.

Here is some supporting code(VB): The parent control(MainResultControl)

Private Sub Submit_Click(ByVal sender As System.Object, _
                         ByVal e As System.EventArgs) Handles tbSubmit.Click
    'a copy of MyRequestArgs is created with the details of request'
    pnlResult.Controls.Add(new ResultsControl(_myRequestArgs))
End Sub

The child control(ResultsControl):

Public Class ResultsControl

  Public _webRequestResult As WebRequestResult      

  Public Sub New(ByVal _requestArgs As MyRequestArgs)

     Dim _service as MyWebService()
     _service.GetTripSolutionsAsync(New TripPlannerParameters() _
                             With {.ApplicationID = _requestArgs.ApplicationID, _
                                   .Arrival = _requestArgs.Parameters.Arrival, _
                                   .Destination = _requestArgs.Parameters.Destination})
  End Sub

  Private Sub _service_GetTripSolutionsCompleted(ByVal sender As Object, _
                                               ByVal e As MyWebService.ResultCompletedEventArgs) Handles _service.GetTripSolutionsCompleted

     'Validation of correct results is done here
     'Skipped for simplicity
     _webRequestResult = DirectCast(e.Result, WebRequestResult)

  End Sub

End Class

EDIT:

I consulted some people and it seems that WCF has some methods of ensuring that event raised from the service is handled by the proper object (on the client machine) that raised it. The idea is - WCF utilizes different IP sockets on the client machine for multiple asynchronous requests. Is that true?

myroslav
  • 1,670
  • 1
  • 19
  • 40

1 Answers1

1

You have to implement some unique marker of the request.

See... I.e. you have control A, so you have to create a Unique Marker/ID for that control and send it.

And under the callback method you have to return that Marker/ID so you can filter messages within a CONTROL.

The best approach is if you will send between client/server some MESSAGE BOX so u can easly add that ID there and error's messages as well.

Something like that...

NoWar
  • 36,338
  • 80
  • 323
  • 498
  • Thanks Peretz. That does make sense to me. Do you know of any design document or article referencing this problem? I just want to know if such behavior is by design - the possibility of results being referenced by a different object than the one that requested it. – myroslav Mar 20 '13 at 19:51
  • @myroslav I am afraid there is no any Docs. Share here more code to analyze. – NoWar Mar 20 '13 at 19:58