questions about using workflow to implement a pageflow in ASP.NET.

Discussion in 'ASP .Net' started by smwikipedia, Mar 26, 2008.

  1. smwikipedia

    smwikipedia Guest

    i send an event through a button on an aspx page to a statemachine workflow
    and then let the workflow to use CallExternalMethod to raise a local service
    event which is booked by a asp.net host method, the method is to change a
    Label control's Text property to a new string.

    here is my code for Local Service:
    =======
    namespace myService
    {

    //host -> wf Define the Interface
    [ExternalDataExchange]
    public interface IService
    {
    event EventHandler<myargs> event_from_host_to_wf;
    void method_from_wf_to_host();
    }


    //myargs derived from ExternalDataEventArgs
    [Serializable]
    public class myargs : ExternalDataEventArgs
    {
    private String _msg;
    public myargs(Guid instanceID, string msg)
    : base(instanceID)
    {
    _msg = msg;
    }

    public String Msg
    {
    get { return _msg; }
    set { _msg = value; }
    }

    }


    //host <-> wf
    public class myServiceClass:IService
    {
    #region IService Members

    public event EventHandler<myargs> event_from_host_to_wf;

    public void method_from_wf_to_host()
    {
    //throw new NotImplementedException();
    event_from_wf_to_host();

    }

    #endregion

    #region Host Members
    public void raise_event_from_host_to_wf(Guid instanceId, string msg)
    {//prepare myargs
    myargs e = new myargs(instanceId, msg);
    event_from_host_to_wf(null, e);
    }

    public delegate void delegate_event_from_wf_to_host();
    public event delegate_event_from_wf_to_host event_from_wf_to_host;

    #endregion
    }
    }

    ===================
    Here is the behind code for page1.aspx
    namespace SimpleChangeWebUI
    {
    public partial class _Default : System.Web.UI.Page
    {

    private WorkflowRuntime _runtime;
    private ManualWorkflowSchedulerService _scheduler;
    private ExternalDataExchangeService _exchangeService;
    private myServiceClass _myServiceClass;
    private bool operation_from_wf_is_recorded = false;
    private ManualResetEvent _waitHandle = new ManualResetEvent(false);

    protected void Page_Load(object sender, EventArgs e)
    {
    btn_create_a_wf_instance.Enabled = true;
    btn_change_UI_through_wf_instance.Enabled = false;

    _runtime = Application["runtime"] as WorkflowRuntime;
    _scheduler =
    _runtime.GetService<ManualWorkflowSchedulerService>();
    _exchangeService =
    _runtime.GetService<ExternalDataExchangeService>();
    _myServiceClass =
    _exchangeService.GetService(typeof(myServiceClass)) as myServiceClass;
    }

    protected void btn_create_a_wf_instance_Click(object sender,
    EventArgs e)
    {
    btn_create_a_wf_instance.Enabled = false;
    btn_change_UI_through_wf_instance.Enabled = true;
    Label1.Text = "a workflow instance has been created!";

    _myServiceClass.event_from_wf_to_host += new
    myServiceClass.delegate_event_from_wf_to_host(change_web_UI);

    WorkflowInstance _instance =
    _runtime.CreateWorkflow(typeof(Workflow1));
    Session.Add("instanceId", _instance.InstanceId);
    _instance.Start();
    _scheduler.RunWorkflow(_instance.InstanceId);

    }

    protected void btn_change_UI_through_wf_instance_Click(object
    sender, EventArgs e)
    {
    Guid _instanceID = (Guid)Session["instanceId"];
    _myServiceClass.raise_event_from_host_to_wf(_instanceID,
    "nothing!");//host å‘ wf å‘出 event!
    _scheduler.RunWorkflow(_instanceID);
    _waitHandle.WaitOne();
    }

    private void change_web_UI()
    {
    Label1.Text = "the Label.Text has been modified through the
    workflow instance";
    }
    }
    }

    =============
    I set breakpoints and find that the change_web_UI() function has been
    undoubtly executed, but disappointingly, the Label.Text remains the same.
    Could anyone tell me why? Is this because the page is rendered before the
    workflow completed?
    but I DO have used the ManualWorkflowSchedulerService in my
    WorkflowRuntime...

    Any suggestion will be deeply appreciated!
    my email is :
    wish somebody would contact me and shed some light on me... :(
     
    smwikipedia, Mar 26, 2008
    #1
    1. Advertising

  2. smwikipedia

    Duy Lam Guest

    smwikipedia wrote:
    > i send an event through a button on an aspx page to a statemachine workflow
    > and then let the workflow to use CallExternalMethod to raise a local service
    > event which is booked by a asp.net host method, the method is to change a
    > Label control's Text property to a new string.
    >
    > here is my code for Local Service:
    > =======
    > namespace myService
    > {
    >
    > //host -> wf Define the Interface
    > [ExternalDataExchange]
    > public interface IService
    > {
    > event EventHandler<myargs> event_from_host_to_wf;
    > void method_from_wf_to_host();
    > }
    >
    >
    > //myargs derived from ExternalDataEventArgs
    > [Serializable]
    > public class myargs : ExternalDataEventArgs
    > {
    > private String _msg;
    > public myargs(Guid instanceID, string msg)
    > : base(instanceID)
    > {
    > _msg = msg;
    > }
    >
    > public String Msg
    > {
    > get { return _msg; }
    > set { _msg = value; }
    > }
    >
    > }
    >
    >
    > //host <-> wf
    > public class myServiceClass:IService
    > {
    > #region IService Members
    >
    > public event EventHandler<myargs> event_from_host_to_wf;
    >
    > public void method_from_wf_to_host()
    > {
    > //throw new NotImplementedException();
    > event_from_wf_to_host();
    >
    > }
    >
    > #endregion
    >
    > #region Host Members
    > public void raise_event_from_host_to_wf(Guid instanceId, string msg)
    > {//prepare myargs
    > myargs e = new myargs(instanceId, msg);
    > event_from_host_to_wf(null, e);
    > }
    >
    > public delegate void delegate_event_from_wf_to_host();
    > public event delegate_event_from_wf_to_host event_from_wf_to_host;
    >
    > #endregion
    > }
    > }
    >
    > ===================
    > Here is the behind code for page1.aspx
    > namespace SimpleChangeWebUI
    > {
    > public partial class _Default : System.Web.UI.Page
    > {
    >
    > private WorkflowRuntime _runtime;
    > private ManualWorkflowSchedulerService _scheduler;
    > private ExternalDataExchangeService _exchangeService;
    > private myServiceClass _myServiceClass;
    > private bool operation_from_wf_is_recorded = false;
    > private ManualResetEvent _waitHandle = new ManualResetEvent(false);
    >
    > protected void Page_Load(object sender, EventArgs e)
    > {
    > btn_create_a_wf_instance.Enabled = true;
    > btn_change_UI_through_wf_instance.Enabled = false;
    >
    > _runtime = Application["runtime"] as WorkflowRuntime;
    > _scheduler =
    > _runtime.GetService<ManualWorkflowSchedulerService>();
    > _exchangeService =
    > _runtime.GetService<ExternalDataExchangeService>();
    > _myServiceClass =
    > _exchangeService.GetService(typeof(myServiceClass)) as myServiceClass;
    > }
    >
    > protected void btn_create_a_wf_instance_Click(object sender,
    > EventArgs e)
    > {
    > btn_create_a_wf_instance.Enabled = false;
    > btn_change_UI_through_wf_instance.Enabled = true;
    > Label1.Text = "a workflow instance has been created!";
    >
    > _myServiceClass.event_from_wf_to_host += new
    > myServiceClass.delegate_event_from_wf_to_host(change_web_UI);
    >
    > WorkflowInstance _instance =
    > _runtime.CreateWorkflow(typeof(Workflow1));
    > Session.Add("instanceId", _instance.InstanceId);
    > _instance.Start();
    > _scheduler.RunWorkflow(_instance.InstanceId);
    >
    > }
    >
    > protected void btn_change_UI_through_wf_instance_Click(object
    > sender, EventArgs e)
    > {
    > Guid _instanceID = (Guid)Session["instanceId"];
    > _myServiceClass.raise_event_from_host_to_wf(_instanceID,
    > "nothing!");//host å‘ wf å‘出 event!
    > _scheduler.RunWorkflow(_instanceID);
    > _waitHandle.WaitOne();
    > }
    >
    > private void change_web_UI()
    > {
    > Label1.Text = "the Label.Text has been modified through the
    > workflow instance";
    > }
    > }
    > }
    >
    > =============
    > I set breakpoints and find that the change_web_UI() function has been
    > undoubtly executed, but disappointingly, the Label.Text remains the same.
    > Could anyone tell me why? Is this because the page is rendered before the
    > workflow completed?
    > but I DO have used the ManualWorkflowSchedulerService in my
    > WorkflowRuntime...
    >
    > Any suggestion will be deeply appreciated!
    > my email is :
    > wish somebody would contact me and shed some light on me... :(



    According to MSDN, the remark of RunWorkflow() method said that "this is
    a synchronous call that uses the current thread to run the workflow. It
    does not return until the workflow idles, suspends, completes,
    derminates, or aborts".

    If your CallExternalMethod activity is put after the ListenerEvent
    activity (sorry, I dont know exactly its name), the change_web_UI()
    method will be called.
    But you should pay little attention to a thing: if the workflow get
    trouble (etc. exception) when operating (running), it will stop
    immediately (you can catch WorkflowTerminated or WorkflowError event to
    know). So if your workflow get any error, it will stop and your method
    won't be called.

    --
    Thanks,
    Duy Lam Phuong
     
    Duy Lam, Mar 26, 2008
    #2
    1. Advertising

  3. smwikipedia

    smwikipedia Guest

    Re: questions about using workflow to implement a pageflow in ASP.


    > > =============
    > > I set breakpoints and find that the change_web_UI() function has been
    > > undoubtly executed, but disappointingly, the Label.Text remains the same.
    > > Could anyone tell me why? Is this because the page is rendered before the
    > > workflow completed?
    > > but I DO have used the ManualWorkflowSchedulerService in my
    > > WorkflowRuntime...
    > >
    > > Any suggestion will be deeply appreciated!
    > > my email is :
    > > wish somebody would contact me and shed some light on me... :(

    >
    >
    > According to MSDN, the remark of RunWorkflow() method said that "this is
    > a synchronous call that uses the current thread to run the workflow. It
    > does not return until the workflow idles, suspends, completes,
    > derminates, or aborts".
    >
    > If your CallExternalMethod activity is put after the ListenerEvent
    > activity (sorry, I dont know exactly its name), the change_web_UI()
    > method will be called.
    > But you should pay little attention to a thing: if the workflow get
    > trouble (etc. exception) when operating (running), it will stop
    > immediately (you can catch WorkflowTerminated or WorkflowError event to
    > know). So if your workflow get any error, it will stop and your method
    > won't be called.
    >
    > --
    > Thanks,
    > Duy Lam Phuong
    >



    thanks for your reply. I run my website in debug mode and set a breakpoint
    in the
    change_web_UI() method, it does be invoked and i checked the VS2008 IDE
    output window, there's no exception or error message. everythings seems just
    fine. can you believe that? i'd like to send you my code through email if
    that won't be too much bothering...my email is , plz
    send me a mail if you are available. thanks a lot. :)
     
    smwikipedia, Mar 26, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Microsoft
    Replies:
    2
    Views:
    774
    Max Akbar
    Feb 5, 2004
  2. Heiner Kücker

    JSP Workflow FlowControl PageFlow Engine

    Heiner Kücker, Nov 25, 2004, in forum: Java
    Replies:
    1
    Views:
    3,064
    Murray
    Nov 25, 2004
  3. Kausar
    Replies:
    1
    Views:
    439
    Richard Carpenter
    Jul 14, 2006
  4. GaryDean

    PageFlow After HTTPs Write

    GaryDean, Jul 15, 2006, in forum: ASP .Net
    Replies:
    7
    Views:
    669
    Steven Cheng[MSFT]
    Jul 19, 2006
  5. Andrzej Jaworek
    Replies:
    1
    Views:
    529
    Alexey Smirnov
    Jul 23, 2007
Loading...

Share This Page