LJB022

I'm new to Windows Workflow Foundation and have been going through the book, Foundations of WF - An introduction to windows workflow foundation, as an attempt to teach myself the fundamentals. So far so good, except I am having the following problem.

For EventDrivenActivities, I can not get the method specified in the invoke property of the activity to fire.

With the code sample provided below, I do not get the msgbox statements to appear that exist in the Workflow subs that are called via the handleexternaleventactivity invoke method. Any help would be greatly appreciated. I can't figure out what I'm doing wrong and this is going to be an essential piece of functionality for an application I've been asked to estimate. Please HELP!

Here is the properties on my handleExternalEventActivity:

Name: HandleReviewNotApproved

Description:

Enabled: True

EventName: ReviewNotApproved

InterfaceType: VBCommunicationSequentialConsoleApplication.IReview

Roles:

Invoked: OnNotApproved

e:

sender:

Here is the code of my workflow:

Public class Workflow1

Inherits SequentialWorkflowActivity

Public Sub OnApproved(ByVal sender As Object, ByVal e As ExternalDataEventArgs)

MsgBox("Approved")

End Sub

Public Sub OnNotApproved(ByVal sender As Object, ByVal e As ExternalDataEventArgs)

MsgBox("Not Approved")

End Sub

End Class

Here is my interface:

<ExternalDataExchange()> _

Public Interface IReview

Event ReviewApproved As EventHandler(Of ExternalDataEventArgs)

Event ReviewNotApproved As EventHandler(Of ExternalDataEventArgs)

Function CreateReview(ByVal reviewer As String, ByVal reviewee As String) As Boolean

End Interface

Here is my class the implements the interface:

Public Class ReviewService : Implements IReview

Private _reviewer As String

Private _reviewee As String

Public Event ReviewApproved(ByVal sender As Object, ByVal e As System.Workflow.Activities.ExternalDataEventArgs) Implements IReview.ReviewApproved

Public Event ReviewNotApproved(ByVal sender As Object, ByVal e As System.Workflow.Activities.ExternalDataEventArgs) Implements IReview.ReviewNotApproved

Public Function CreateReview(ByVal reviewer As String, ByVal reviewee As String) As Boolean Implements IReview.CreateReview

_reviewer = reviewer

_reviewee = reviewee

MsgBox("Reviewer: " & reviewer)

ThreadPool.QueueUserWorkItem(New System.Threading.WaitCallback(AddressOf AskForApproval))

Return True

End Function

Private Sub ApproveReview(ByVal sender As Object, ByVal e As ExternalDataEventArgs) Handles Me.ReviewApproved

MsgBox("Reviewer: " & _reviewer & " has approved the review for " & _reviewee)

End Sub

Public Sub DoNotApproveReview(ByVal sender As Object, ByVal e As ExternalDataEventArgs) Handles Me.ReviewNotApproved

MsgBox("Reviewer: " & _reviewer & " has NOT approved the review for " & _reviewee)

End Sub

Public Sub AskForApproval(ByVal o As Object)

' Without a listen activity the WF terminates here.

If MsgBox("Do you approve the review for: " & _reviewee & " ", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then

RaiseEvent ReviewApproved(Nothing, Nothing)

Else

RaiseEvent ReviewNotApproved(Nothing, Nothing)

End If

End Sub

End Class



Re: Windows Workflow Foundation HandleExternalEvent Activity not firing invoke method - HELP!

SonaliC

The problem is RaiseEvent ReviewApproved(Nothing, Nothing).

While raising an event, you need to specify the instanceId of the workflow to which you are sending the event, in ExternalDataEventArgs parameter.

e.g. Here is the code to raise event from Listen Sample in WF Samples

RaiseEvent OrderApproved(Nothing, New OrderEventArgs(instanceId.InstanceId, orderId))

For more details refer communications samples

.Net3.0 : http://msdn2.microsoft.com/en-us/library/ms741731.aspx

Orcas : http://msdn2.microsoft.com/en-us/library/ms741731(vs.90).aspx






Re: Windows Workflow Foundation HandleExternalEvent Activity not firing invoke method - HELP!

Tom Lake - MSFT

Try using the following updated ReviewService:

Public Class ReviewService : Implements IReview

Private _reviewer As String

Private _reviewee As String

Public Event ReviewApproved(ByVal sender As Object, ByVal e As System.Workflow.Activities.ExternalDataEventArgs) Implements IReview.ReviewApproved

Public Event ReviewNotApproved(ByVal sender As Object, ByVal e As System.Workflow.Activities.ExternalDataEventArgs) Implements IReview.ReviewNotApproved

Public Function CreateReview(ByVal reviewer As String, ByVal reviewee As String) As Boolean Implements IReview.CreateReview

_reviewer = reviewer

_reviewee = reviewee

MsgBox("Reviewer: " & reviewer)

'Pass the current workflow instance id as the state

ThreadPool.QueueUserWorkItem(New System.Threading.WaitCallback(AddressOf AskForApproval), WorkflowEnvironment.WorkflowInstanceId)

Return True

End Function

Private Sub ApproveReview(ByVal sender As Object, ByVal e As ExternalDataEventArgs) Handles Me.ReviewApproved

MsgBox("Reviewer: " & _reviewer & " has approved the review for " & _reviewee)

End Sub

Public Sub DoNotApproveReview(ByVal sender As Object, ByVal e As ExternalDataEventArgs) Handles Me.ReviewNotApproved

MsgBox("Reviewer: " & _reviewer & " has NOT approved the review for " & _reviewee)

End Sub

Public Sub AskForApproval(ByVal o As Object)

' Use the incoming object, which is the instance id, to create the external data event args.

Dim e As ExternalDataEventArgs = New ExternalDataEventArgs(DirectCast(o, Guid))

If MsgBox("Do you approve the review for: " & _reviewee & " ", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then

RaiseEvent ReviewApproved(Nothing, e)

Else

RaiseEvent ReviewNotApproved(Nothing, e)

End If

End Sub

End Class






Re: Windows Workflow Foundation HandleExternalEvent Activity not firing invoke method - HELP!

LJB022

This make sense. I've made the changes you suggested, and the instanceID has a value. However, the application is still not invoking the methods in the workflow. I've taken a look at the Listen example, and that works. I'm not sure what's wrong with the example that I am working on, but there must be something else missing that I'm not seeing.

Thanks.





Re: Windows Workflow Foundation HandleExternalEvent Activity not firing invoke method - HELP!

Tom Lake - MSFT

I am using the following workflow and the Invoked handler is getting called properly, Workflow2.xoml:

<SequentialWorkflowActivity x:Class="WorkflowConsoleApplication41.Workflow2" x:Name="Workflow2" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/workflow">

<CallExternalMethodActivity x:Name="callExternalMethodActivity1" InterfaceType="{x:Type WorkflowConsoleApplication41.IReview}" MethodName="CreateReview">

<CallExternalMethodActivity.ParameterBindings>

<WorkflowParameterBinding ParameterName="(ReturnValue)">

<WorkflowParameterBinding.Value>

<ActivityBind Name="Workflow2" Path="returnValue" />

</WorkflowParameterBinding.Value>

</WorkflowParameterBinding>

<WorkflowParameterBinding ParameterName="reviewee">

<WorkflowParameterBinding.Value>

<ActivityBind Name="Workflow2" Path="reviewee" />

</WorkflowParameterBinding.Value>

</WorkflowParameterBinding>

<WorkflowParameterBinding ParameterName="reviewer">

<WorkflowParameterBinding.Value>

<ActivityBind Name="Workflow2" Path="reviewer" />

</WorkflowParameterBinding.Value>

</WorkflowParameterBinding>

</CallExternalMethodActivity.ParameterBindings>

</CallExternalMethodActivity>

<ListenActivity x:Name="listenActivity1">

<EventDrivenActivity x:Name="eventDrivenActivity1">

<HandleExternalEventActivity Invoked="OnApproved" x:Name="handleExternalEventActivity1" EventName="ReviewApproved" InterfaceType="{x:Type WorkflowConsoleApplication41.IReview}" />

</EventDrivenActivity>

<EventDrivenActivity x:Name="eventDrivenActivity2">

<HandleExternalEventActivity Invoked="OnNotApproved" x:Name="handleExternalEventActivity2" EventName="ReviewNotApproved" InterfaceType="{x:Type WorkflowConsoleApplication41.IReview}" />

</EventDrivenActivity>

</ListenActivity>

</SequentialWorkflowActivity>

Workflow2.xoml.vb:

Public Class Workflow2

Inherits SequentialWorkflowActivity

Public Sub OnApproved(ByVal sender As Object, ByVal e As ExternalDataEventArgs)

MsgBox("Approved")

End Sub

Public Sub OnNotApproved(ByVal sender As Object, ByVal e As ExternalDataEventArgs)

MsgBox("Not Approved")

End Sub

Public returnValue As System.Boolean = Nothing

Public reviewee As System.String = "reviewee"

Public reviewer As System.String = "reviewer"

End Class