title: How to host the Windows Workflow as a Web service(.svc)?
body: <p>I am trying to host the windows workflow as a web service, below is the sample workflow that I built and would like to host as a web service(.svc), can you please suggest the required steps?</p>
  
  <pre><code>using System;
  using System.ServiceModel.Activities;
  using System.Activities;
  using System.ServiceModel;
  using System.Activities.Statements;
  
  namespace DemoWF
  {
      public class _25_LeaveRequest
      {
          public WorkflowService GetInstance()
          {
              WorkflowService service;
              Variable&lt;int&gt; empID = new Variable&lt;int&gt; { Name = "empID" };
              Variable&lt;int&gt; requestID = new Variable&lt;int&gt; { Name = "requestID" };
  
          Receive receiveLeaveRequest = new Receive
          {
              ServiceContractName = "ILeaveRequestService",
              OperationName = "ApplyLeave",
              CanCreateInstance = true,
              Content = new ReceiveParametersContent
              {
                  Parameters ={
                      {"empID",new OutArgument&lt;int&gt;(empID)}
                  }
              }
          };
  
          SendReply replyLeaveRequestID = new SendReply
          {
              Request = receiveLeaveRequest,
              Content = new SendParametersContent
              {
                  Parameters ={
                              {"requestID",new InArgument&lt;int&gt;(requestID)},
                          },
              },
          };
  
  
          Sequence workflow = new Sequence()
          {
              Variables = { empID, requestID },
              Activities = {
                  new WriteLine{Text="WF service is starting..."},
                  receiveLeaveRequest,
                  new WriteLine{
                      Text=new InArgument&lt;string&gt;(aec=&gt; "Emp ID="+empID.Get(aec).ToString())
                  },
                  new Assign&lt;int&gt;{
                      Value=new InArgument&lt;int&gt;(5),
                      To=new OutArgument&lt;int&gt;(requestID)
                  },
                  new WriteLine{
                      Text=new InArgument&lt;string&gt;(aec=&gt; "Request ID="+requestID.Get(aec).ToString())
                  },
                  replyLeaveRequestID
              },
          };
  
          service = new WorkflowService
          {
              Name = "AddService",
              Body = workflow
          };
          return service;
      }
  }
  </code></pre>
  
  <p>Right now, it is self hosted as highlighted below</p>
  
  <pre><code>namespace DemoWF
  {
      class Program
      {
          static void Main(string[] args)
          {
              LeaveRequest();
          }
  
          private static void LeaveRequest()
          {
              _25_LeaveRequest receiveAndReplyWorkflow = new _25_LeaveRequest();
              WorkflowService wfService = receiveAndReplyWorkflow.GetInstance();
              Uri address = new Uri("http://localhost:8000/WFServices");
              WorkflowServiceHost host = new WorkflowServiceHost(wfService, address);
  
              try
              {
                  Console.WriteLine("Opening Service...");
                  host.Open();
  
                  Console.WriteLine("WF service is listening on " + address.ToString() + ", press any key to close");
                  Console.ReadLine();
              }
              catch (Exception e)
              {
                  Console.WriteLine("some thing bad happened" + e.StackTrace);
              }
              finally
              {
                  host.Close();
              }
          }
      }
  }
  </code></pre>