locked
How to invoke method on external instance object in WF4 RRS feed

  • Question

  • I'm migrating my WF3 state machine workflows to WF4 flowcharts. In WF3, I was using events sent to the host to execute methods on an object in the host. In WF4, I'm trying to use the InvokeMethod to achieve this by passing in a reference to the object, but I'm unable to get a reference to the object recognized by the workflow in the InvokeMethod activity.

    My approach was to set up an argument to the workflow of the object's type, which is a WPF Frame object.:

    Dictionary<string, object> param = new Dictionary<string, object>();
    param.Add("frame", this.Frame);
    wf = new WorkflowApplication(new MyActivity(), param);

    I then use InvokeMethod in the workflow with TargetObject set to frame and MyMethod as the MethodName. Everything seems fine and compiles but the method does not get called. It seems that the 'frame' object gets silently ignored.

    When I changed the invocation of the workflow to:

    wf = new WorkflowApplication(new MyActivity() { frame = this.Frame } );

    I then see the error: "'Literal<MyFrame>': Literal only supports value types, and the immutable type System.String. The type System.Windows.Controls.Frame cannot be used as a literal". Thus it appears I can pass in only value types to a workflow in this manner.

    Is there any way to get a reference to an object external to the workflow into an InvokeMethod activity? If not, is this because of threading issues? If not, is there some other approach I can use to have a workflow to invoke methods in the code hosting the workflow?

     

    Friday, March 26, 2010 4:30 PM

Answers

  • It will only accept serializable arguments. If you need to pass any parameters from frame object then define a serializable type and pass it in the argument.
    • Marked as answer by Steve Conrad Saturday, March 27, 2010 10:17 PM
    • Unmarked as answer by Steve Conrad Saturday, March 27, 2010 10:18 PM
    • Marked as answer by Steve Conrad Saturday, March 27, 2010 10:18 PM
    Saturday, March 27, 2010 6:41 PM

All replies

  • It will only accept serializable arguments. If you need to pass any parameters from frame object then define a serializable type and pass it in the argument.
    • Marked as answer by Steve Conrad Saturday, March 27, 2010 10:17 PM
    • Unmarked as answer by Steve Conrad Saturday, March 27, 2010 10:18 PM
    • Marked as answer by Steve Conrad Saturday, March 27, 2010 10:18 PM
    Saturday, March 27, 2010 6:41 PM
  • Thanks. The Frame object itself is what I'm trying to pass in as an argument to the workflow. It appears that it is not marked serializable, so that may be the reason it does not make it through.

    I've ended up taking another approach, by setting up a static class and method to manipulate the frame object. It is working, but I'm now limited to manipulating a single workflow instance (but perhaps I can modify the static class to manage a list of workflows).

    Saturday, March 27, 2010 10:23 PM