配置时[WebMethod(EnableSession = true)] //启用会话
public string UserList1()
{
    System.Threading.Thread.Sleep(1000 * 60 * 5); //模似计算5分钟
    return "abc1";
}[WebMethod(EnableSession = true)] //启用会话
public string UserList2()
{
    return "abc2";
}在我的程序中只有登陆与退出才会对会话进行写,其他时候都是只读(主要是权限),
因此在页面 EnableSessionState="ReadOnly" 这样配置,而如果是实现IHttpHandler接口的对象则再加这个
System.Web.SessionState.IReadOnlySessionState接口,都能很好的解决问题.但在WEB服务方面,就不知道如何解决了同一会话(不同实例,不同模块,异步等)调用以上两个方法
先调用1再调用2,2会被阻塞到1完成才返回,但放在页面上就没有问题(只要配置EnableSessionState).解决过的朋友帮助一下!

解决方案 »

  1.   

    好像EnableSessionState只能用到Page上。我也不知道web service能不能设置,但是wcf是可以设置Concurrency的
      

  2.   

    这是wcf的设置[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)]
    class MultipleCachingHttpFetcher : IHttpFetcher
      

  3.   

    好像web service是不行的:State ManagementWeb services state can be specific to a user or to an application. Web services use ASP.NET session state to manage per-user data and application state to manage application-wide data. You access session state from a Web service in the same way you do from an ASP.NET application — by using the Session object or System.Web.HttpContext.Current. You access application state using the Application object, and the System.Web.HttpApplicationState class provides the functionality.Maintaining session state has an impact on concurrency. If you keep data in session state, Web services calls made by one client are serialized by the ASP.NET runtime. Two concurrent requests from the same client are queued up on the same thread in the Web service — the second request waits until the first request is processed. If you do not use session data in a Web method, you should disable sessions for that method.Maintaining state also affects scalability. First, keeping per-client state in-process or in a state service consumes memory and limits the number of clients your Web service can serve. Second, maintaining in-process state limits your options because in-process state is not shared by servers in a Web farm.If your Web service needs to maintain state between client requests, you need to choose a design strategy that offers optimum performance and at the same time does not adversely affect the ability of your Web service to scale. The following guidelines help you to ensure efficient state management:* Use session state only where it is needed.
    * Avoid server affinity.Use Session State Only Where It Is NeededTo maintain state between requests, you can use session state in your Web services by setting the EnableSession property of the WebMethod attribute to true, as shown in the following code snippet. By default, session state is disabled.[WebMethod(EnableSession=true)]
    YourWebMethod() { ... }
    Since you can enable session state at the Web method level, apply this attribute only to those Web methods that need it.Note   Enabling session state pins each session to one thread (to protect session data). Concurrent calls from the same session are serialized once they reach the server, so they have to wait for each other, regardless of the number of CPUs.
    Avoid Server AffinityIf you do use session state, in-process session state offers the best performance, but it prevents you from scaling out your solution and operating your Web services in a Web farm. If you need to scale out your Web services, use a remote session state store that can be accessed by all Web servers in the farm.以上来自msdn:
    http://msdn.microsoft.com/en-us/library/ff647786.aspx
      

  4.   

    我三楼的文章转自msdn,不是说了吗,用了Session就没法concurrency了。看这段,忘加颜色了。Maintaining session state has an impact on concurrency. If you keep data in session state, Web services calls made by one client are serialized by the ASP.NET runtime. Two concurrent requests from the same client are queued up on the same thread in the Web service — the second request waits until the first request is processed. If you do not use session data in a Web method, you should disable sessions for that method.可以使用WCF.
      

  5.   

     [WebMethod(EnableSession = true)]
     public object[] MethodInvoke(object[] objArr)
      

  6.   

    WEB Service的方法也可以如上进行配置,启用Session
      

  7.   

    感谢findcaiyzh 一早为我答题,看来只能换一种思路了.