Groups > Asp .Net > Advanced ASP.NET Architecture > Questions about implement a pageflow with WFF in ASP.net




Questions about implement a pageflow with WFF in ASP.net

Questions about implement a pageflow with WFF in ASP.net
Wed, 26 Mar 2008 13:08:41 +000
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 : smwikipedia@gmail.com
wish somebody would contact me and shed some light on me...  :(
Post Reply
about | contact