How to access Application [] collection from WCF web service

I used to use .ASMX web services, but I'm trying to migrate to WCF because this is the newest new thing and should be better.

Anyway, what I want to do is really very simple: create a web service that frees the collection of applications by calling Application.Clear (). In an ASMX web service, this is really very easy because .ASMX web services have full access to the Application [] collection. However, this does not work in WCF.

So here's my service contract:

[ServiceContract]
public interface IFlusherServicePage
{
    [OperationContract]
    void FlushApplicationCache();
}

      

Here's my implementation class:

public class FlusherServicePage : Page, IFlusherServicePage
{
    public void FlushApplicationCache()
    {
        Application.Clear();
    }
}

      

And here is my .svc file:

<%@ ServiceHost Language="C#" Debug="true" Service="FlusherServicePage" CodeBehind="~/App_Code/FlusherServicePage.cs" %>

      

Everything compiles fine. However, when I call my web service, FlushApplicationCache () throws a NullReferenceException because Application [] is null.

Is there a way to access Application [] collection from WCF web service? Or do I need to go back to .ASMX?

+1


source to share


1 answer


While WCF can run on the same AppDomain as ASP.Net, it doesn't go through the entire ASP.Net pipeline. So the HttpContext is not set and you cannot get into the application. WCF services have been decoupled from ASP.Net pending deployment in WAS Server 2008.



0


source







All Articles