2011-03-03 67 views
1

我有一個由接收活動和SendReply活動組成的活動。接收活動等待消息,然後將其寫出到控制檯,然後發送答覆。如何從本地活動中的計劃活動獲取OutArgument?

問題是我無法從接收活動完成時收到消息。

下面是我的活動類和異常信息。

public sealed class MyActivity : NativeActivity 
{ 
    private Receive Receive { get; set; } 
    private SendReply SendReply { get; set; } 

    private Variable<CorrelationHandle> CorrelationHandle { get; set; } 
    private Variable<string> MessageParameter { get; set; } 
    private Variable<string> ResponseParameter { get; set; } 

    public MyActivity() 
    { 
     CorrelationHandle = new Variable<CorrelationHandle>("SenseProcessCorrelationHandle"); 
     MessageParameter = new Variable<string>("MessageParamter"); 
     ResponseParameter = new Variable<string>("ResponseParam"); 

     Receive = new Receive 
     { 
      ServiceContractName = XName.Get("{http://tempuri.org/}MyService"), 
      OperationName = "Trigger", 
      Content = new ReceiveParametersContent 
      { 
       Parameters = 
       { 
        { "Message", new OutArgument<string>(MessageParameter) }, 
       }, 
      }, 
      CanCreateInstance = true, 
      CorrelationInitializers = 
      { 
       new RequestReplyCorrelationInitializer 
       { 
        CorrelationHandle = new InArgument<CorrelationHandle>(CorrelationHandle), 
       } 
      } 
     }; 

     SendReply = new SendReply 
     { 
      Request = Receive, 
      Content = new SendMessageContent 
      { 
       Message = new InArgument<string>(ResponseParameter), 
      } 
     }; 

    } 

    protected override void Execute(NativeActivityContext context) 
    { 
     context.ScheduleActivity(Receive, OnReceiveCompleted); 
    } 

    void OnReceiveCompleted(NativeActivityContext context, ActivityInstance inst) 
    { 

     /* Next code line throws exception 
     * 
     * Activity '2: MyActivity' cannot access this variable because it is 
     * declared at the scope of activity '2: MyActivity'. An activity 
     * can only access its own implementation variables. 
     */ 
     Console.WriteLine(MessageParameter.Get(context));    

     context.ScheduleActivity(SendReply); 
    } 

    protected override void CacheMetadata(NativeActivityMetadata metadata) 
    { 
     metadata.AddChild(Receive); 
     metadata.AddChild(SendReply); 
     metadata.AddVariable(CorrelationHandle); 
     metadata.AddVariable(ResponseParameter); 
     metadata.AddVariable(MessageParameter);    
    } 
} 

如果有人知道我做錯了什麼,我將不勝感激任何幫助。

感謝

回答

1

您必須輸入的,而不是你的代碼驗證碼:

CorrelationInitializers = 
{     
    new RequestReplyCorrelationInitializer 
    { 
     CorrelationHandle = CorrelationHandle 
    }   
} 

其中第二CorrelationHandle是您的變量沒有做出新的inargument。

相關問題