Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > questions about using workflow to implement a pageflow in ASP.NET.

Reply
Thread Tools

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

 
 
smwikipedia
Guest
Posts: n/a
 
      03-26-2008
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(chan ge_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(_insta nceID,
"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 : http://www.velocityreviews.com/forums/(E-Mail Removed)
wish somebody would contact me and shed some light on me...
 
Reply With Quote
 
 
 
 
Duy Lam
Guest
Posts: n/a
 
      03-26-2008
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(chan ge_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(_insta nceID,
> "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 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.

--
Thanks,
Duy Lam Phuong
 
Reply With Quote
 
 
 
 
smwikipedia
Guest
Posts: n/a
 
      03-26-2008

> > =============
> > 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 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.
>
> --
> 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 (E-Mail Removed), plz
send me a mail if you are available. thanks a lot.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Windows Workflow Foundation Web Workflow Approvals Starter Kit: problem Andrzej Jaworek ASP .Net 1 07-23-2007 11:32 AM
PageFlow After HTTPs Write GaryDean ASP .Net 7 07-19-2006 02:24 AM
Implement Singleton Using or Not Using dynamic object. Steven Woody C++ 2 12-29-2005 03:07 AM
JSP Workflow FlowControl PageFlow Engine Heiner Kcker Java 1 11-25-2004 11:08 PM
Re: Questions....questions....questions Patrick Michael A+ Certification 0 06-16-2004 04:53 PM



Advertisments