我正在尝试在Windows工作流基础4.5中构建一个简单的请假申请,当工作流尝试完成而不等待approveRequest活动时,它会抛出以下异常。
具有相同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();
}
}
}
}
答案 0 :(得分:0)
您可能有两个具有相同名称的方法,它们接收两个参数。但是,由于您将对象发送到WF服务,因此可以将这些对象强制转换为其中一种方法,因此WF服务无法知道要执行哪一种。
作为第一步,你应该改变你的离开&#39; method会在您的服务中重载签名,因此不需要:
public object ApplyLeave(SomeType1 t1, SomeType2 t2) {...}
public object ApplyLeave(SomeType3 t3, SomeType4 t4) {...}
成功:
public object ApplyLeaveA(SomeType1 t1, SomeType2 t2) {...}
public object ApplyLeaveB(SomeType3 t3, SomeType4 t4) {...}
在你的代码中调用你想要使用的确切方法。