Using system;
Using system. Data;
Using system. configuration;
Using system. collections;
Using system. Web;
Using system. Web. Security;
Using system. Web. sessionstate;
Using system. workflow. Activities;
Using system. workflow. runtime;
Using system. workflow. runtime. Hosting;
Using system. Collections. Specialized;
Namespace webservice1
{
Public class Global: system. Web. httpapplication
{
Protected void application_start (Object sender, eventargs E)
{
System. workflow. runtime. workflowruntime = new system. workflow. runtime. workflowruntime ("workflowruntime ");
// System. workflow. runtime. hosting. sqlworkflowpersistenceservice sqlpersistenceservice = new system. workflow. runtime. hosting. sqlworkflowpersistenceservice ("Initial catalog = sqlpersistenceservice; Data Source = localhost; Integrated Security = sspi ");
// Workflowruntime. addservice (sqlpersistenceservice );
Workflowruntime. workflowaborted + = new eventhandler <system. workflow. runtime. workfloweventargs> (workflowruntime_workflowaborted );
Workflowruntime. workflowidled + = new eventhandler <system. workflow. runtime. workfloweventargs> (workflowruntime_workflowidled );
Workflowruntime. workflowterminated + = new eventhandler <system. workflow. runtime. workflowterminatedeventargs> (workflowruntime_workflowterminated );
Workflowruntime. workflowunloaded + = new eventhandler <system. workflow. runtime. workfloweventargs> (workflowruntime_workflowunloaded );
Workflowruntime. workflowsuincluded + = new eventhandler <system. workflow. runtime. workflowsuspendedeventargs> (workflowruntime_workflowsuincluded );
Workflowruntime. workflowcompleted + = new eventhandler <system. workflow. runtime. workflowcompletedeventargs> (workflowruntime_workflowcompleted );
Namevaluecollection parms = new namevaluecollection ();
Parms. Add ("unloadonidle", "true ");
Parms. Add ("connectionstring", configurationmanager. connectionstrings ["sqlconnectionstring"]. connectionstring );
Workflowruntime. addservice (New sqlworkflowpersistenceservice (parms ));
// String conn = configurationmanager. connectionstrings ["sqlconnectionstring"]. connectionstring;
// Workflowruntime. addservice (New sqlworkflowpersistenceservice (conn ));
Application ["workflowruntime"] = workflowruntime;
Workflowruntime. startruntime ();
}
Void workflowruntime_workflowcompleted (Object sender, system. workflow. runtime. workflowcompletedeventargs E)
{
Console. writeline ("finished ");
}
Void workflowruntime_workflowsuincluded (Object sender, system. workflow. runtime. workflowsuspendedeventargs E)
{
Console. writeline ("pending ");
}
Void workflowruntime_workflowunloaded (Object sender, system. workflow. runtime. workfloweventargs E)
{
Console. writeline ("Uninstall ");
}
Void workflowruntime_workflowterminated (Object sender, system. workflow. runtime. workflowterminatedeventargs E)
{
Console. writeline ("Abort ");
}
Void workflowruntime_workflowidled (Object sender, system. workflow. runtime. workfloweventargs E)
{
Console. writeline ("idle ");
}
Void workflowruntime_workflowaborted (Object sender, system. workflow. runtime. workfloweventargs E)
{
Console. writeline ("unexpected ");
}
Protected void application_end (Object sender, eventargs E)
{
System. workflow. runtime. workflowruntime = application ["workflowruntime"] As system. workflow. runtime. workflowruntime;
Workflowruntime. stopruntime ();
}
}
}