Getting Host Variables

Im wondering if anyone can help me.

I am hosting Windows Workflow in ASP.NET. In ASP.NET I am using NHibernate. NHibernate has a run time variable that is created when the web app starts up that all the sessions use to create querys, etc. Its a good practice to only have ony application variable because of 2nd level caching, etc.

My question is how would I go about getting access to this application variable inside windows workflow. I cant pass the variable becuase the workflow my hyderate, etc. Is there anyway I could go to the host context and get a application variable

I guess I am looking for something like..

wwf.host.application["variable"]

Thanks in advance,

Mardo



Answer this question

Getting Host Variables

  • baaba

    Are you executing in the context of a page request being processed If so, then yes, you should have a context. That being said, if you are jumping into the process to early, then the context might not be setup yet. Where are you using this code

    Matt



  • James E Freedle II

    Razi, I appreciate the reply. However one of the things about the workflow is a lot of times it will serialize to the database. Something like a session factory handling connections does not do well with serialization.

    The http context is what I was looking for, thank you all.

    Mardo


  • Xancholy

    In order to use variable inside workflow you have to decalre public properties inside worklow class , consider the following vode fragment

    //UserName is public property in workflow class

    Dictionary<string, object> parameters = new
    Dictionary<string, object>();
    parameters.Add("UserName", UserName.Text);

    WorkflowInstance instance = wr.CreateWorkflow(t, parameters);

    the above code shows how to set paramerters that can be send to workflow if you have futher need to send some paramerter out from work flow you can use

    OutputParameters["parameterName"] to get it.



  • Francois JEAN

    No, the HttpContext is only populated during request processing. If this activity is raised from a timer, then it is most likely not on a request and will have no context. In that case, you'll need to find another way to get at the current application or cache. You might try giving your local service a reference to one of these, but know that both will be invalidated when the application recycles, and it will. In that case, you might want to provide this reference at application startup in the same code where you add your local service to the runtime. Have a property or constructor where you can provide a reference to the HttpApplication that you are currently in so you can use it to access the application state.

    Matt



  • Pon_teh_pony

    System.Web.HttpContext.Current.Application

    Does not work, Current= null. Hmmm.. Should this work

    Mardo


  • gogoYang

    If you are executing in the context of ASP.NET and you know that, you can use HttpContext.Current to get at the current context, current application, request, response, etc. Just make sure you check that the current property of the context is not null.

    You might also consider factoring this out into a local service so you can reuse it provide different implementations for other hosts. For example, your local service in a win form app might actually store the values directly in its own hashtable, while the asp.net implementation would simply use the application object.

    Matt



  • Sneha

    Matt,

    I am using this code within the activities of the workflow (only activities I added). I guess as far as the context is conernced. At first it is instantiated from a web page, but other times it could hyderate from a timer elapse.

    I figured if it was hosted in the w3 process it would always have that http context available.

    Mardo



  • Getting Host Variables