Custom Activity - Probelm with EventSink Activity

Hello,

i tried to model a custom activity. This activity does contain of
a) InvokeMethod Activity
b) EventSink Activity
out of the activity galery delivered. I also implemented a Service which I added to the workflow engine in order to connect the method invokation and the event sink.

Then I build up a sequntial wf out of my custom activity.
The method invoke activity within my custom activity works properly, but when
my async. operation is finished and I want to raise the event to trigger the eventsink activity the event within the added service was null.

The same scenario works fine when i model this directly within a sequential wf.
Regards
CHS

[690 byte] By [CHS] at [2008-2-22]
# 1

You need to make sure that the event is raised for the appropriate instance of the workflow. I am pasting some sample code that I wrote.

[DataExchangeService]
public interface Service
{
void SomeMethod();
event EventHandler<WorkflowMessageEventArgs> SomeEvent;
}

public class ServiceImpl : ClassLibrary1.Service
{
public WorkflowInstance instanceId;
public event System.EventHandler<WorkflowMessageEventArgs> SomeEvent;

public void SomeMethod()
{
ThreadPool.QueueUserWorkItem(new WaitCallback(RaiseSomeEvent),new WorkflowMessageEventArgs(instanceId.InstanceId));
}

private void RaiseSomeEvent(object state)
{
WorkflowMessageEventArgs e = (WorkflowMessageEventArgs)state;
if (SomeEvent != null)
{
Console.WriteLine("Raising some event for instanceID " + e.InstanceId);
SomeEvent(
null, e);
}
}
}

And in your host you need to do the following:

WorkflowRuntime workflowRuntime = new WorkflowRuntime();
ServiceImpl implLayer = new ServiceImpl();
workflowRuntime.AddService(implLayer);
workflowRuntime.StartRuntime();

Type type = typeof(WorkflowConsoleApplication2.Workflow1);
implLayer.instanceId = workflowRuntime.StartWorkflow(type);

Hope this helps.

- Vihang

vihang at 2007-9-9 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 2
Hello,

thank you for the information. The code you have pasted is the same code that I have implemented, but this code only works if I use the MethodInvoke Activity and EventSink Activity directly within a sequntial workflow.

What I tried then is to make a custom activity that contains also a MethodInvoke and a EventSink activity. The service (like the code above) I have to register at the workflow level. But when I use then this custom activity withina sequential WF the MethodInvoke does work, but the EventSink does not, because when i reach the code in my service implemntation where I want to fir the event that is sinked by mey eventsink activity within my custom activity in your code

private void RaiseSomeEvent(object state)
{
WorkflowMessageEventArgs e = (WorkflowMessageEventArgs)state;
if (SomeEvent != null)
{
Console.WriteLine("Raising some event for instanceID " + e.InstanceId);
SomeEvent(null, e);
}
}
}

The SomeEvent is always NULL?!

So can I not transfere the MethodInvoke and the EventSink activity into a cuistom activity?! Is there also the problem with persisting child activities?!

Regards
CHS

CHS at 2007-9-9 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 3

My original code was from the scenario that you have mentioned (custom activity with InvokeMethod and EventSink used in workflow). This could be an issue with Beta1 bits. I am unable to repro the error that you are seeing with the latest bits. I remember that there was issue with EventSink activity in Beta1 if the interface is in the same file as the activity. Try having the interface and its implementation in a separate code file in the same project as the custom activity. Then create the custom activity and use it in a workflow in a second project. Let me know if this works.

Thanks,

Vihang

vihang at 2007-9-9 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 4
Hello,
I think you forgot to set "InterfaceType" and "EventName" in your "eventSink" properties.
Regards
Philippe31 at 2007-9-9 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...

Software Development for Windows Vista

Site Classified