How to get ActivityExecutionContext from a CodeActivity or any CallExternalMethodActivity?

For any derived Activity that can override Execute() method, you can get ActivityExecutionContext object of current activity, but how do I get ActivityExecutionContext for the ones that can not or don't want to override Execute()?

I try to pass/useActivityExecutionContextManageror ActivityExecutionContext from parent activity, but got runtime error "Cannot access a disposed object". They must be an easy way to access ActivityExecutionContext given a reference of acitvity object, could anybody please tell me how?

Thanks.

[651 byte] By [Lj47] at [2007-12-24]
# 1
Where do you want it? If you aren't overriding Execute - in what method are you trying to access the AEC?
JonFlanders at 2007-8-31 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 2

For exmple, I have a derived class MyActivity from CallExternalMethodActivity, and I want to access my ExternalDataExchangeService object inside MyActivity's overrided method CallExternalMethodActivity::OnMethodInvoking(EventArgs e). But I don't want to persist ExternalDataExchangeService object as a property. The only way I know is to get ExternalDataExchangeService object from ActivityExecutionContext.GetSerivce<T>() call, then I need to access ActivityExecutionContext first.

From any given ActivityExecutionContext, you can easily access its owner activity through ActivityExecutionContext.Activity property. I will be really surprised that there is no way to get ActivityExecutionContext object from any given Activity object.

Thanks.

Lj47 at 2007-8-31 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 3

My guess is that the designers of CallExternalMethodActivity did this on purpose (made Execute sealed and don't pass the AEC to the overridable methods). Why not write your own custom activity that calls the method on your Local Service interface?

If you build custom activities - you are right - you can almost always get the AEC. If you derive from another class - you are limited to the access the base class implementor created for you.

JonFlanders at 2007-8-31 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 4

Jon, thanks for your comments. The main reason I derive CallExternalMethodActivity is that I use CorrelationParameter. If I don't derive it then I have to implement queuing myself, and CallExternalMethodActivity already handle all these for me nicely by using CorrelationToken.

Looks like if the base activity does not dispose Execute() method, then I have no way to access AEC, that's bad, I have to find other way to workaround it.

Thanks again.

Lj47 at 2007-8-31 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 5
Have you looked at using wca.exe, the workflow communication activity generator, to generate custom communication activities that inherit from CallExternalMethodActivity and HandleExternalEventActivity. This wouldn't give you access to the AEC, but it would allow you to use correlation and all of the features of the CallExternalMethod and HandleExternalEventActivity.
MattWinkler--MSFT at 2007-8-31 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...

Software Development for Windows Vista

Site Classified