instantiating an object from a web service vs instantiating an object from a regular class

后端 未结 3 1839
礼貌的吻别
礼貌的吻别 2021-01-05 16:30

I have a very basic web service:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace          


        
3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-05 16:51

    Becaue on the server side the class is created and disposed with EVERY call you make from the client... your client is just a "proxy" and doesn't correspond directly to an instance on the server side...

    You can either make myInt static or make the server side service class a Singleton... both options would mean that myIntis shared across ALL client... or you could implement some session management to achieve a client-specific myInt... using WCF for the server side seems IMHO the best solution - it comes with configurable options for singleton, session management etc.

    EDIT - as per comments:

    With WCF you can have .NET-clients with session management which in turn allows you to have different (client-specific) values for myInt...

提交回复
热议问题