Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / March 2008

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
smwikipedia - 26 Mar 2008 09:37 GMT
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...  :(
Duy Lam - 26 Mar 2008 15:31 GMT
> 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
[quoted text clipped - 139 lines]
> my email is : smwikipedia@gmail.com
> 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.

Signature

Thanks,
Duy Lam Phuong

smwikipedia - 26 Mar 2008 16:58 GMT
> > =============
> > I set breakpoints and find that the change_web_UI() function has been
[quoted text clipped - 21 lines]
> 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 smwikipedia@gmail.com, plz
send me a mail if you are available. thanks a lot.  :)

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.