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

S

smwikipedia

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 : (e-mail address removed)
wish somebody would contact me and shed some light on me... :(
 
D

Duy Lam

smwikipedia said:
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 : (e-mail address removed)
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.
 
S

smwikipedia

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 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 (e-mail address removed), plz
send me a mail if you are available. thanks a lot. :)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top