Raising Events from the Service in the Workflow Runtime
Hi,
I have the following interface in my workflow application.
[ExternalDataExchange]
public interface ILoginService
{
event EventHandler<LogInEventArgs> LogInSubmitted;
event EventHandler<LoginResultsEventArgs> LoginPerformed;
void PerformLogin(object sender, LogInEventArgs loginData);
}
I have a simple login form (browser application). The user interface adds an handler to the LoginPerformed event. This is how the whole scenario works.
- Once the workflow starts I add an implementation of this (ILoginService) into the runtime. The workflow listens for an event of type LogInSubmitted. The user interface registers an handler to LoginPerformed.
- When the user clicks the submit button on the login form an event of type LogInSubmitted is raised. The workflow will now call the PerformLogin method.
- PerformLogin will then call LogInSubmitted once complete.
- This in turn will call the regitered handler in the user interface.
The problem is that although PerformLogin raises the LoginPerformed event, the registered handler on the browser does not get called. The workflow runtime seems to be swallowing up this event in some way. However if I just remove the service from the runtime and call the PerformLogin method directly from the user interface then the registered handler gets called nicely.
Am I missing something here?
[1479 byte] By [
Arjuna_M] at [2007-12-21]
Arjuna - I am suspecting the behavior is because there are three different threads running simultaneously and the method invocation from Workflow is delivered to the non-app runtime thread <which might be why you see the runtime swallowing the event>.
You could, on the app event handler, check if the current thread can process the event being raised by using "this.InvokeRequired" and on true create an instance of the delegate and "this.Invoke" it. On false you can do whatever processing needs to be done on the event.
Having said that, on step 3 did you mean to say the PerformLogin will then call LoginPerformed event once complete?
Take a look at the samples > OrderingStateMachine sample on how to do this precisely. Hope that helps.
_Vignesh
Hi,
I had a look at the OrderingStateMachine example and it has one way communication in the form of.
ClientApplication->Call Service Method->Service Method RaiseEvent->Workflow Responds.
What I am looking for is something in the form of
ClientApplication->Call Service Method->Service Method RaiseEvent to which Workflow Listens->Workflow Responds.(This is ok)
Workflow->Call Service Method->Service Method RaiseEvent to which Client Application Listens->Client Application Responds. This is the method that does not work. Basically the Event Handling method on the Client Application does not get called. How do I fix this.
The Client Application is a Browser Application (Not an ASP.NET Application).
Basically what I want to do is for the Client Application to submit a login method through a Servcie and continue work. When the Workflow finishes the login operation it will raise an event on the Service to which the Client Application will respond to.
Thanks
Arjuna.
Hi,
I did some futher testing on this and this is the error I get when the Service tries to raise events to which the Client Application has subscribed to.
"Event \"LoginPerformed\" on interface type \"SQLClientWorkflow.ILoginService\" for instance id \"1df34076-e7e0-41e6-9d4a-359df2dbd003\" cannot be delivered."
However if I mark the event handler on the Client Application as static then it seeems to work fine, does anyone have any idea on this.