Hi,
I'm gradually introducing CSLA into our existing application. It's a MVC / Silverlight app using WCF services hosted in IIS.
For each WCF call, the existing code creates and stores an EF DbContext in HttpContext that is then used for the duration of that call (the DbContext is created / destroyed in the HttpApplication's BeginRequest / EndRequest event handlers).
As I'm gradually adding CSLA business objects into the mix, I've come across an issue where the HttpContext.Current ends being null within the DataPortal XYZ methods. I need access to HttpContext so that my CSLA business objects (from their server-side DataPortal XYZ methods) can calls some of the pre-existing code that relies on HttpContext containing the EF DbContext used for managing database access.
Below is an example of the code I'm using:
public async static Task<ReportQuery> ExecuteAsync(ReportCriteria criteria)
{
var cmd = new ReportQuery { ReportCriteria = criteria };
cmd = await DataPortal.ExecuteAsync<ReportQuery>(cmd);
return cmd;
}
protected async override void DataPortal_Execute()
{
// This is where System.Web.HttpContext.Current is NULL
}
I added breakpoints to the HttpApplication's BeginRequest and EndRequest event handlers (that are wrapped around the call to my CSLA DataPortal XYZ methods), and was able to confirm that HttpContext.Current did contain a 'real' value. Unfortunately, this HttpContext does not make its way further down the chain to the CSLA DataPortal XYZ methods.
I've tried quite a few things,but no luck yet. I made sure to include the following in Web.config, to ensure that HttpContext is accessible within WCF:
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
Any ideas?
Thanks,
Pete