When using a workflow service, we typically use message activities such as receive in the workflow design and then host using WorkflowServiceHost, and the workflow cannot accept messages sent if there is no receive activity. This time we can use the Workflowhostingendpoint class:
To host a workflow without a service, you need to inherit workflowhostingendpoint and rewrite Ongetinstanceid,ongetcreationcontext,onresolvebookmark. First we declare a service contract, which contains a service operation that creates a new instance, which passes a idictionary<string,object> parameter implicitly implemented by Workflowhostingendpoint. When this workflow is hosted, it is added using the WorkflowServiceHost AddServiceEndpoint method. The following examples illustrate:
1. The following is the project structure:
2. Define the service contract first, as follows:
[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", IsOneWay = true)]
void ResumeBookmark(Guid instanceId, string bookmarkName, string message);
}