views:

268

answers:

3

I used to use .ASMX web services, but I'm trying to move to WCF because it's the latest newest thing, and it's supposed to be better.

Anyway, what I'm wanting to do is really really simple : create a webservice that empties the Application collection by calling Application.Clear(). In an ASMX web service, this is really really simple, because .ASMX webservices have full access to the Application[] collection. However, this doesn't really work in WCF.

So, here's my service contract :

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

Here's my implementing class :

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

And here's my .svc file :

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

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

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

A: 

I should also mention that I've tried using ASP.NET compatibility mode. This provides access to the Session[] collection, but not the Application[] collection.

A: 

Even though WCF can run in the same AppDomain as ASP.Net, it does not go through the full ASP.Net pipeline. As such, the HttpContext is not set and you cannot get to the application. WCF Services have been separated from ASP.Net in anticipation of being hosted in the WAS of Server 2008.

Overloaded Constructor
A: 

Huh. Interesting. I guess then I'll just have to go with ASMX for this... I think it's curious that there are still things that ASMX can do that WCF cannot do, because it seems like they're trying to deprecate ASMX. Do you know if they'll be supporting it in the future?