Windows Vista Beta | WinVistaBeta.com - Message | WF EventHandling Problem

September 07, 2008  
Subject: WF EventHandling Problem
Group: microsoft.public.windows.developer.winfx.sdk
Date: 9/20/2006 3:11:01 AM
From: =?Utf-8?B?U3VuYXRo?= [Email Address Protection]

Hi WF Gurus,

Im having a problem in eventhandling using dynamically loading assemblies.
That time the value of the event is gettin NULL.

So just for checking,I tried the same in the ORDERINGSTATEMACHINE
Sample.There also im having the same issue that the OrderCreated event is
gettin NULL value.In the sample, Instead of calling the
RaiseOrderCreatedEvent method like this...

orderService.RaiseOrderCreatedEvent(orderId, workflowInstanceId);

Im calling the event by creating the services dynamically and adding it to a
hashtable and making the object for the orderservice class during runtime and
calling the RaiseOrderCreatedEvent Method.

Everything is working fine but the value of the OrderCreated event is
getting NULL.Otherwise without loading assemblies dynamically,the event is
not gettin null and its working fine.

Please help me to figure out whats happening wrong here.. For ur kind
reference, im giving the code sample of what all changes i did in the
sample...



private void StartWorkflowRuntime()

{

workflowRuntime = new WorkflowRuntime();

workflowRuntime.WorkflowTerminated += new
EventHandler<WorkflowTerminatedEventArgs>(WorkflowRuntime_WorkflowTerminated);

workflowRuntime.WorkflowCompleted += new
EventHandler<WorkflowCompletedEventArgs>(WorkflowRuntime_WorkflowCompleted);

workflowRuntime.WorkflowIdled += new
EventHandler<WorkflowEventArgs>(workflowRuntime_WorkflowIdled);

// Add the External Data Exchange Service

ExternalDataExchangeService dataExchangeService = new
ExternalDataExchangeService();

workflowRuntime.AddService(dataExchangeService);

HTService = new Hashtable();

orderService = new OrderService();


dataExchangeService.AddService(orderService);


LoadServices();

workflowRuntime.StartRuntime();

}


private void LoadServices()

{

SqlConnection con = new SqlConnection();

con.ConnectionString = @"Data Source=devserver;Initial Catalog=sample;User
ID=sa;Password=pass";

SqlCommand cmd = new SqlCommand();

SqlDataReader reader;

cmd.Connection = con;

cmd.CommandType = CommandType.Text;

cmd.CommandText = "select assemblyname from orderservice";



try

{

if (con.State == System.Data.ConnectionState.Closed)

{

con.Open();

}

reader = cmd.ExecuteReader();

using (reader)

{

while (reader.Read())

{

// Process SprocResults datareader here.

assem = reader["assemblyname"].ToString();

}

}

}

finally

{

// reader.Close();

}

Type ServiceType;

Assembly *** = Assembly.LoadFrom(assem);

try

{

ServiceType = ***.GetType(classnam, true, true);

objService = Activator.CreateInstance(ServiceType);

}

catch (Exception e)

{

MessageBox.Show(e.Message);

}

if (objService is OrderService)

{

workflowRuntime.AddService(objService);

HTService["order"] = objService;

}


}



private void btnOrderCreated_Click(object sender, EventArgs e)

{

// Get the OrderId that was entered by the user

string orderId = this.txtOrderID.Text;

// Start the Order Workflow

System.Guid workflowInstanceId =

this.StartOrderWorkflow();


// Raise an OrderCreated event using the Order Local Service

OrderService objService = (OrderService)HTService["order"];

objService.RaiseOrderCreatedEvent(orderId, workflowInstanceId);

}



The RaiseOrderCreatedEvent is gettin called but the OrderCreated event is
getting value NULL hence the event is not gettin FIRED!...

Waiting 4 ur valuable thoughts to fix this issue...

Thanks in advance

Sunath


--
Imagination is more powerful than knowledge!!

Back