2012-03-30 39 views
1

我建立一個(瘦)客戶端 - 服務器應用程序與IIS的使用Spring.Net作爲主要技術和薄WPF演示客戶端通過WCF comunicating服務器服務器(我們計劃客戶在未來的Web版本) 當我登錄我創建一個HTTP會話cookie有一個像網頁瀏覽器有狀態會話,我從服務器獲取許可證。 當我註銷,或者如果IIS會話超時(因爲客戶端崩潰或用戶不能正確登出)我需要:IIS,Spring.Net WCF HTTP會話管理

  • 發行許可證
  • 釋放所有的會話從服務器RAM範圍內的對象。

所以我需要實現這兩點:

  • 鉤到EndSession事件來處理超時和崩潰
  • 其通信的會議結束時釋放的後IIS中的註銷過程執照。

我在網上看過,但沒有找到一個關於如何做這種雙向會話管理的明確例子。如果你能幫助我,併爲IIS的XML配置的例子,Spring.Net將不勝感激

FYI這是出現在我的web.config文件中的主要WCF和WEB配置:

<system.serviceModel> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" /> 

    <bindings> 
    <basicHttpBinding> 
     <binding name="basicHttpBinding1" maxReceivedMessageSize="31457280" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:30:00" sendTimeout="00:30:00"> 
     <readerQuotas maxStringContentLength="31457280" maxArrayLength="31457280" /> 
     </binding> 
    </basicHttpBinding> 
    </bindings> 

    <services> 
    <service name="wcfService" behaviorConfiguration="DefaultBehavior"> 
     <endpoint address="" binding="basicHttpBinding" contract="Nemsys.SMF.Service.Tunnel.IWCFService" /> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
    </service> 
    </services> 

    <behaviors> 
    <serviceBehaviors> 
     <behavior name="DefaultBehavior"> 
     <serviceMetadata httpGetEnabled="True" /> 
     <serviceDebug includeExceptionDetailInFaults="True" /> 
     </behavior> 
    </serviceBehaviors> 
    </behaviors> 
</system.serviceModel> 

<system.web> 
    <compilation debug="true" targetFramework="4.0" /> 

    <sessionState timeout="60" /> 

    <!-- needed by Spring.Net on IIS 7.0 --> 
    <httpHandlers> 
    <add verb="*" path="*.aspx" type="Spring.Web.Support.PageHandlerFactory, Spring.Web" /> 
    </httpHandlers> 
    <httpModules> 
    <add name="Spring" type="Spring.Context.Support.WebSupportModule, Spring.Web" /> 
    </httpModules> 
</system.web> 

<!-- needed by Spring.Net on IIS 7.0 --> 
<system.webServer> 
    <validation validateIntegratedModeConfiguration="false" /> 
    <modules> 
    <add name="Spring" type="Spring.Context.Support.WebSupportModule, Spring.Web" /> 
    </modules> 
    <handlers> 
    <add name="SpringPageHandler" verb="*" path="*.aspx" type="Spring.Web.Support.PageHandlerFactory, Spring.Web" /> 
    <add name="SpringContextMonitor" verb="*" path="ContextMonitor.ashx" type="Spring.Web.Support.ContextMonitor, Spring.Web" /> 
    </handlers> 
</system.webServer> 

其實我已經設法通過在管理用戶會話的BLL類中實現IDisposable來正確釋放Logout或Http Session過期的資源,並在處理對象之前調用它。 ,我不知道該怎麼做的唯一事情是: 當用戶釋放我需要摧毀HTTP會話讓IIS和Spring收集並釋放所有的會話資源分配到的許可證後,點擊退出按鈕。

+1

恕我直言,這不是Spring.NET的關係。如果你在IIS上並使用一個asp.net Session,你可以創建一個global.asax並使用'protected void Session_End(Object sender,EventArgs e)'來清除。 – Andreas 2012-03-30 09:13:33

+1

根據你的更新'SessionState.Abandon();'是你的朋友。 http://msdn.microsoft.com/en-us/library/system.web.sessionstate.httpsessionstate.abandon.aspx – Andreas 2012-03-30 15:26:21

回答

1

這是我做的: 配置好春聽IIS事件在我的會話使用案例的退出方法我稱之爲

public void Logout() 
    { 
     HttpContext.Current.Session.Abandon(); 
    } 

這由Andreas的建議觸發結束會話事件,告訴Spring,所有會話作用域對象都可以被垃圾回收。 我管理用戶會話的用例也實現了IDisposable接口,並在釋放對象之前調用Dispose()方法。 在這種方法中,我聯繫了一個許可證用例(這是一個單例),要求他釋放許可證。

+0

這個作品在我的調試環境,但在生產中設法不調用Dispose()方法時,它 – 2012-06-07 09:55:25