I'm new to WF4. What I want to do is to expose WF4 state machine as a WCF service.I have created the state machine. How can I execute the transition triggers and change the status using WCF. http://channel9.msdn.com/Shows/Workflow-TV/endpointtv-WF4-State-Machine-Hands-On-Lab-Exercise-2 . This is the tutorial I have used to create the state machine.
2 Answers
I wrote a sample that shows how to do this at State Machine Security Door. Basically you just use Send/ReceiveReply pairs in the transitions.

- 3,279
- 2
- 18
- 16
-
Thanks for the guide. I have a question about your sample. Is there a reason to put the service in the web project? We are using websinc(http://www.frozenmountain.com/websync/) server to call the services from silverlight. – Jayantha Lal Sirisena Feb 16 '12 at 04:56
-
XAMLX files must be hosted either in a web project or you can self host them with WorkflowServiceHost. – Ron Jacobs Feb 23 '12 at 19:16
-
So , what you are saying is we don't need to use separate server like websync to use WF services with silverlight. Thanks for the help. – Jayantha Lal Sirisena Feb 23 '12 at 19:23
-
Workflows cannot be hosted with Silverlight. They require the .NET Runtime so they must be hosted in another server process in this case. – Ron Jacobs May 24 '12 at 13:20
If u don't want send and receive activity's it's possible with some work. The send and receive activity's can be hard to write for end customers doing correlation stuff. The other side is that it would be alot better if there was a generic entrance for the client so the client doesn't need to have a updated service reference, but only a contract definition.
We removed all correlation and created a generic webservice that re-route to a specific xamlx workflow, but not using send/receive activities. Instead we use bookmarks inside a xamlx workflow. So we created a own activity to receive custom pageflow data and another activity to send data back to the instance. The only problem we had.
public interface IWorkflowService
{
#region State Machine / Pageflow Operations
[OperationContract]
IPageflowData Start(IPageflowData pageflowData);
[OperationContract(Name = "StartWithInputs")]
IPageflowData Start(IPageflowData pageflowData, IDictionary<string, object> inputs);
[OperationContract]
IPageflowData Resume(PageflowCommand command, IPageflowData pageflowData);
[OperationContract(Name = "ResumeWithExecuteCommand")]
IPageflowData Resume(string commandName, IPageflowData pageflowData);
[OperationContract]
IPageflowData ResumeTo(string stepName, IPageflowData pageflowData);
#endregion
This is combined with dynamic endpoints as available in the WF samples called WorkflowCreationEndpoint implementing the IworkflowCreation contract.
[ServiceContract(Name = "IWorkflowCreation")]
public interface IWorkflowCreation
{
[OperationContract(Name = "Create")]
Guid Create(IDictionary<string, object> inputs);
[OperationContract(Name = "CreateWithInstanceId", IsOneWay = true)]
void CreateWithInstanceId(Guid instanceId, IDictionary<string, object> inputs);
[OperationContract(Name = "ResumeBookmark")]
void ResumeBookmark(Guid instanceId, string bookmarkName, object bookmarkValue);
}

- 2,219
- 1
- 25
- 51