views:

589

answers:

1

I'm having trouble finding any worthwhile documentation on the new version of WorkflowServiceHost that ships with .NET 4 / VS 2010 Beta 2.

The new version of the WorkflowServiceHost now lives in System.ServiceModel.Activities and has different contructors than the old, .NET 3.x version that lived in System.ServiceModel.

I want to be able to load my workflow by passing in the type like this previous constructor in the .NET 3.x version allowed...

public WorkflowServiceHost(Type workflowType, params Uri[] baseAddress)

My issue is that I don't have the information any of the other contructors need at compile time (I was planning to infer the Type of my workflow via Type.GetType(string) as I will only have access to the actual Workflow activities at runtime).

Is there any other way that I can host a workflow that has been loaded at runtime?

Thanks for all your help in advance :)

+1  A: 

In WF4 you pass the actual workflow definition as an activity tree instead of a type as you did before. If you have the type creating an object should be simple using something like Activator.CreateInstance(). Using an activity tree instead of a type has some benefits because you can create the objects on the fly of use the ActivityXamlServices.Load() to read a XAML file.

The WCF part of the WorkflowServiceHost can be done completely in the config file if you like. No need to pass a baseAddress in with the constructor.

An alternative to the WorkflowServiceHost is using a WorkflowApplication. This still requires you to add an activity tree into the constructor though.

Maurice
Thanks for your reply Maurice - I don't seem to have any luck with the Activator.CreateInstance() route either - I receive runtime exceptions when I try and pass it into the WorkflowServiceHost(object serviceObject, params Uri[] baseAddresses) like this 'WorkflowServiceHost requires that the serviceObject provided is an Activity or a WorkflowService.Parameter name: serviceObject'.I can't go down the ActivityXamlServices.Load() route either, as my workflow service is provided as a dll binary and not a xaml/xmalx.Any other ideas?Many thanks once again
Lygpt
The type points to an Activity right? If so cast it so an Activity before passing it into the WorkflowServiceHost constructor. Now you are using the wrong overload as Activator.CreateInstance() returns it as type Object.
Maurice
That worked great thanks Maurice - I had to do some fiddling but (Activity) Activator.CreateInstance(Type.GetType("Namespace.ClassName, Assembly")).Thanks once again
Lygpt