2017-05-01 1 views
7

Windows 워크 플로 파운데이션 4.5에 간단한 휴가 요청 응용 프로그램을 만들려고합니다. 워크 플로가 approveRequest 작업을 기다리지 않고 완료하려고 할 때 다음 예외가 throw됩니다.Windows 워크 플로 기반의 인간 기반 작업

동일한 ServiceContractName 및 OperationName 'ApplyLeave'가있는 두 개의 SendParameters 개체는 서로 다른 매개 변수 이름을 갖습니다.

무엇이 누락 되었습니까?

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

아래에 언급 한 바와 같이 개최했다. 그러나 WF 서비스에 개체를 전송하면 해당 메서드 중 하나에 개체를 전송할 수 있으므로 WF 서비스는 개체를 실행할 수 있는지 여부를 알 수 없습니다. 당신이 당신의 '떠나'방법을 변경해야합니다 첫 번째 단계로

이 서비스에 서명을 오버로드, 그래서 대신 갖는 :

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) {...} 

을 그리고 당신의 코드를 호출에서 당신이 사용하고자하는 정확한 방법.

+0

귀중한 의견을 보내 주셔서 감사합니다. –

+0

환영합니다. 도움이 되었기 때문에 기쁩니다. –

관련 문제