7
我想在Windows工作流基礎4.5中建立一個簡單的請假申請,它會引發以下異常,因爲工作流試圖完成而無需等待approveRequest活動。基於人的任務在Windows工作流基礎
具有相同ServiceContractName和 的兩個SendParameters對象OperationName'ApplyLeave'具有不同的參數名稱。
您能否建議我缺少什麼?
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<int> empID = new Variable<int> { Name = "empID" };
Variable<int> requestID = new Variable<int> { Name = "requestID" };
Receive receiveLeaveRequest = new Receive
{
ServiceContractName = "ILeaveRequestService",
OperationName = "ApplyLeave",
CanCreateInstance = true,
Content = new ReceiveParametersContent
{
Parameters ={
{"empID",new OutArgument<int>(empID)}
}
}
};
SendReply replyLeaveRequestID = new SendReply
{
Request = receiveLeaveRequest,
Content = new SendParametersContent
{
Parameters ={
{"requestID",new InArgument<int>(requestID)},
},
},
};
Receive approveRequest = new Receive
{
ServiceContractName = "ILeaveRequestService",
OperationName = "ApproveLeave",
CanCreateInstance = true,
Content = new ReceiveParametersContent
{
Parameters ={
{"requestID",new OutArgument<int>(requestID)}
}
}
};
SendReply sendApproval = new SendReply
{
Request = receiveLeaveRequest,
Content = new SendParametersContent
{
Parameters ={
{"approved",new InArgument<int>(0)},
},
},
};
Sequence workflow = new Sequence()
{
Variables = { empID, requestID },
Activities = {
new WriteLine{Text="WF service is starting..."},
receiveLeaveRequest,
new WriteLine{
Text=new InArgument<string>(aec=> "Emp ID="+empID.Get(aec).ToString())
},
new Assign<int>{
Value=new InArgument<int>(5),
To=new OutArgument<int>(requestID)
},
new WriteLine{
Text=new InArgument<string>(aec=> "Request ID="+requestID.Get(aec).ToString())
},
replyLeaveRequestID,
approveRequest,
new WriteLine{Text="Approved"},
sendApproval
},
};
service = new WorkflowService
{
Name = "AddService",
Body = workflow
};
return service;
}
}
}
及以下
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();
}
}
}
}
謝謝你的寶貴意見,它有幫助。 –
不客氣:)我很高興這有幫助。 –