views:

318

answers:

1

Ok, so I may be approaching this incorrectly but essentially I'm trying to play with new WF services in 4.0 to build up to a Windows service that hosts a WF service. At the moment I have constructed client (containing a simple Activity XAML) and service (WF service implemented in a XAMLX file) projects.

I have tried simple "hello worlds" for each one. The client has been hosted in a WorkflowApplication and I initially setup the service as the default WF service project template. Both seem to be fine there.

Since I want to host a service without IIS, naturally my next attempt was to host my service in a WorkflowServiceHost. Doing this I can use XamlServices.Load() and pass the object it returns to the WorkflowServiceHost constructor along with a URI for the endpoint. I was concerned because that there is no Run() member method like there is in the WorkflowApplication class. I assumed that the Open() method would open the service host object as a service and that it would start an instance of the workflow but there is no indication of it.

At first I setup the service workflow to simply write to a text file when it started but nothing happened. I tried to debug with breakpoints but since it is loading a XAMLX file at runtime, VS doesn't allow me to debug the WF. So I tried altering the client project a bit to use a WorkflowServiceHost instead of a WorkflowApplication. I used the same workflow used to test out the hello world style workflow and this time there was no output to console and the WorkflowApplication was successful with that previously.

Here's the very basics of what I did with the client to host the workflow service in the console project. If anyone wants to see the XAML for the workflow let me know and I'll update this question. Here's the hosting code in Main().

const String clientAddress = "http://localhost:9998/Client";    
WorkflowServiceHost wfHost = new WorkflowServiceHost( new ClientWf(), new Uri(clientAddress) );
wfHost.Open();

while( Console.ReadKey().KeyChar.ToString().ToUpper() != "X" ) {    }

wfHost.Close();
A: 

What I found out is that since you cannot directly start the WF instance that is wrapped by the WorkflowServiceHost object, its a bit of a pain to run it and pretty much impossible by a simple method call like you can accomplish with a WorkflowApplication. There is a "trick" to have the WF fire but takes a bit of a hacking that I haven't given time to at this juncture. MSDN has an obscure reference of what you can do in this scenario here, under Hosting Non-Service Workflows.

This is the solution that I went with: using both the WorkflowServiceHost AND the WorkflowApplication. Why you ask? Well because I was trying to do a whole lot of everything in one tiny little package. I'm also building this as a custom service model for my work and it's better that I separate the business logic (WorkflowApplication) from all of the communication implementation (WorkflowServiceHost). The service fires just fine this way because of course now my underlying comm. workflow starts with a receive activity and WorkflowSericeHosts look for some type of messaging activity at the root of the associated workflow in order to start an instance.

Now I'm a happy camper. My business logic does what it's supposed to do as expected and the workflow service is fleshing out nicely. What's even better is that I have a model where I can dynamically drop in business logic to setup and deploy custom data processing/crunching services dynamically. Now just to perfect call backs to up date a remote "dashboard", that's what I'm moving on to next.

jlafay