Matthias
Matthias

Reputation: 5764

Singleton WebService (ASMX, not WCF)

Is there a way to define an C# ASMX WebService as singleton? Maybe in the Web.config file? Currently I'm not using WCF.

Thanks in advance

    [WebService(Namespace = "http://www.mydomain.eu/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    public class MyService : System.Web.Services.WebService
    {
        ...
    }

Upvotes: 0

Views: 1228

Answers (3)

Tanel
Tanel

Reputation: 314

You can always make the main data object also static and it will be shared through all the worker instances.

Upvotes: 0

Steven
Steven

Reputation: 172696

You can hide your web service behind a facade that is a singleton:

public static class ServiceFacade
{
    public static void ServiceOperation()
    {
        using (var service = new MyService())
        {
            service.Operation();
        }
    }
}

Upvotes: 1

gzaxx
gzaxx

Reputation: 17600

You can't create Singleton web service, because web service runs on IIS and is treated as web app and is maintained as such. Each client will share single application instance, but each of them will have own Request, Response, Session etc.

Upvotes: 0

Related Questions