Used to let an Activity communicate with services provided through the WorkflowRuntime.
If a ExternalDataExchange interface is used in a parallel way it needs to be decorate using the CorrelationParameterAttribute and the functions using the CorrelationInitializerCorrelationParameterAttribute and the CorrelationAliasCorrelationParameterAttribute.
They will ensure that each event is routed to the proper activity.
<ExternalDataExchange()> _
Public Interface IDemoDataExchange
Sub SendSomeData(ByVal theData As String)
Event ReceiveSomeData(ByVal sender As Object, ByVal e As ReceiveSomeDataEventArgs)
End Interface
Public Class DemoDataExchange
Implements IDemoDataExchange
Public Event ReceiveSomeData(ByVal sender As Object, ByVal e As ReceiveSomeDataEventArgs) Implements IDemoDataExchange.ReceiveSomeData
Public Sub SendSomeData(ByVal theData As String) Implements IDemoDataExchange.SendSomeData
Dim state As New SendSomeDataState(WorkflowEnvironment.WorkflowInstanceId, theData)
ThreadPool.QueueUserWorkItem(AddressOf InternalSendSomeData, state)
End Sub
Private Sub InternalSendSomeData(ByVal stateObj As Object)
Dim state As SendSomeDataState = stateObj
Console.WriteLine(state.theData)
Dim reply As String = Console.ReadLine()
Dim args As New ReceiveSomeDataEventArgs(state.instanceId, reply)
RaiseEvent ReceiveSomeData(Nothing, args)
End Sub
Private Class SendSomeDataState
Public instanceId As Guid
Public theData As String
Public Sub New(ByVal instanceId As Guid, ByVal theData As String)
Me.instanceId = instanceId
Me.theData = theData
End Sub
End Class
End Class
<Serializable()> _
Public Class ReceiveSomeDataEventArgs
Inherits ExternalDataEventArgs
Public Sub New(ByVal instanceId As Guid, ByVal reply As String)
MyBase.New(instanceId)
_reply = reply
End Sub
Private _reply As String
Public ReadOnly Property Reply() As String
Get
Return _reply
End Get
End Property
End Class