跟踪 WCF wsDualHttpBinding 上下文中的客户端

发布于 2024-12-10 15:57:40 字数 2153 浏览 3 评论 0原文

我在wcf服务中使用wsDualHttpBinding,并使用以下代码来存储客户端通道:

    public static void Subscribe()
    {
        try
        {
            // Subscribe the guest to the beer inventory
            var guest = OperationContext.Current.GetCallbackChannel<ILoggingServiceCallBack>();

            if (!CallbackList.Contains(guest))
            {
                CallbackList.Add(guest);
            }
        }
        catch (Exception ex)
        {
            //do stuff
        }
        finally
        {
           //do stuff
        }

    }

并且我像这样回调客户端:

        public static void LoggingCallBack(Action<ILoggingServiceCallBack> callbackNotification)
    {
        try
        {
            if (OperationContext.Current != null)
            {
                var guest = OperationContext.Current.GetCallbackChannel<ILoggingServiceCallBack>();
                if (!CallbackList.Contains(guest))
                {
                    CallbackList.Add(guest);
                }
            }

            foreach (var LoggingCallBack in CallbackList)
            {

       var temp = LoggingCallBack;
                try
                {
                    new Thread(() =>
                    {
                        try
                        {
                            callbackNotification(temp);
                        }
                        catch (Exception ex)
                        {
                            //do something
                        }
                    }).Start();


                }
                catch (Exception ex)
                {
                    //do somethin
                }
            }
        }
        catch (Exception ex)
        {
            //doing something
        }
        finally
        {
         //doing something
        }
    }

我遇到了一些麻烦:

  1. 在调用之前我无法判断客户端是否在线 它回来了。
  2. 我需要能够在没有活动后删除客户端 列出我想,如果我达到第一名,我就能做到这一点。
  3. 识别客户的最佳方法是什么,换句话说,什么是 我可以用来识别客户的最佳唯一标识符?
  4. 如果与客户端的连接出现故障我不知道如何检测 并从客户端启动新的一个,就好像我尝试这样做它拒绝并抛出连接故障的异常一样。

抱歉,如果我问了多个问题,请对我发布的代码以及上述任何问题的任何答案发表意见。

I use wsDualHttpBinding in a wcf service, and i use the following code to store client channels:

    public static void Subscribe()
    {
        try
        {
            // Subscribe the guest to the beer inventory
            var guest = OperationContext.Current.GetCallbackChannel<ILoggingServiceCallBack>();

            if (!CallbackList.Contains(guest))
            {
                CallbackList.Add(guest);
            }
        }
        catch (Exception ex)
        {
            //do stuff
        }
        finally
        {
           //do stuff
        }

    }

and i call back clients like that:

        public static void LoggingCallBack(Action<ILoggingServiceCallBack> callbackNotification)
    {
        try
        {
            if (OperationContext.Current != null)
            {
                var guest = OperationContext.Current.GetCallbackChannel<ILoggingServiceCallBack>();
                if (!CallbackList.Contains(guest))
                {
                    CallbackList.Add(guest);
                }
            }

            foreach (var LoggingCallBack in CallbackList)
            {

       var temp = LoggingCallBack;
                try
                {
                    new Thread(() =>
                    {
                        try
                        {
                            callbackNotification(temp);
                        }
                        catch (Exception ex)
                        {
                            //do something
                        }
                    }).Start();


                }
                catch (Exception ex)
                {
                    //do somethin
                }
            }
        }
        catch (Exception ex)
        {
            //doing something
        }
        finally
        {
         //doing something
        }
    }

im running through some troubles:

  1. i have no way to tell if the client is online or not before i call
    it back.
  2. i need to be able to remove the client after no activity from the
    list i guess i would be able to do that if i achieved number 1.
  3. what is the best way to identify clients, in other words what is
    the best unique identifier i can identify the client with?
  4. if a connection with the client faulted i don't know how to detect
    that and start new one from the client as if i tried to do that it refuse to and it throw exception that the connection is faulted.

sorry if i have asked more than one question, please give your opinion about the code i posted and any answer to any question of the above.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文