简体   繁体   English

Singleton WebService(ASMX,不是WCF)

[英]Singleton WebService (ASMX, not WCF)

Is there a way to define an C# ASMX WebService as singleton? 有没有一种方法可以将C#ASMX WebService定义为单例? Maybe in the Web.config file? 也许在Web.config文件中? Currently I'm not using WCF. 目前,我没有使用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
    {
        ...
    }

You can hide your web service behind a facade that is a singleton: 您可以将Web服务隐藏在单例的门面后面:

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

You can't create Singleton web service, because web service runs on IIS and is treated as web app and is maintained as such. 您无法创建Singleton Web服务,因为Web服务在IIS上运行,并被视为Web应用程序,并以此进行维护。 Each client will share single application instance, but each of them will have own Request, Response, Session etc. 每个客户端将共享一个应用程序实例,但是每个客户端将拥有自己的请求,响应,会话等。

您始终可以使主数据对象也成为静态对象,并且它将在所有辅助实例之间共享。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM