简体   繁体   English

使用 WCF 服务的 WPF 应用程序的会话超时

[英]Session Timeout for WPF application using WCF service

Need help for WPF application..需要 WPF 应用程序的帮助..

The application uses WCF service to allow user to log in and do other database transactions.该应用程序使用 WCF 服务来允许用户登录并执行其他数据库事务。 The client wants the application to log out the user if there is a session time out.如果会话超时,客户端希望应用程序注销用户。

Was able to add a function on the forms load event to check if the user is logged in and display the timeout message and log out the user.能够在表单加载事件上添加一个函数来检查用户是否登录并显示超时消息并注销用户。

Have created a base class for the forms and have a overridable Onload event of the form, using this event I am able to have all the forms checked if the user is logged in.为表单创建了一个基类,并有一个可覆盖的表单 Onload 事件,如果用户登录,我可以使用此事件检查所有表单。

Problem :问题 :

When the user is on a form and when there is a session timeout when the user is on the form.当用户在表单上时以及当用户在表单上时会话超时。 When the user clicks on a button or a drop down which would trigger a call to the WCF service the application would give error as the session has timeout.当用户单击按钮或下拉菜单会触发对 WCF 服务的调用时,应用程序将在会话超时时出错。

I would either have to validate if the user is logged in on every function and control event that would call the WCF service.我要么必须验证用户是否登录到将调用 WCF 服务的每个函数和控件事件。

Is there a way like similar to the web page load event which is always being called on every event on the page using which we can have the application check if the user is logged in or not.有没有类似于网页加载事件的方法,该事件总是在页面上的每个事件上调用,使用它我们可以让应用程序检查用户是否登录。

Your help on this would be of great help你在这方面的帮助会有很大帮助

You can listen to all the RoutedEvents like below.您可以收听如下所示的所有RoutedEvents But this will called for all the events (I mean ALL the events) so you can put the check on the particular RoutedEvents like Button.ClickEvent or ComboBox.SelectionChanged但这将调用所有事件(我的意思是所有事件),因此您可以检查特定的RoutedEventsButton.ClickEventComboBox.SelectionChanged

    public MainWindow()
    {
        InitializeComponent();
        RoutedEvent[] events = EventManager.GetRoutedEvents();

        if(events!=null)
        {
           foreach (RoutedEvent e in events)
            AddHandler(e, new RoutedEventHandler(GenericHandler),true);
         }

    }

    private void GenericHandler(object sender, RoutedEventArgs routedEventArgs)
    {
         if (routedEventArgs.RoutedEvent == ButtonBase.ClickEvent || 
            routedEventArgs.RoutedEvent == Selector.SelectionChangedEvent)
        {
            //Here you can check for if user is logged on or not. 
        }

    }

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

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