如何使用 net.tcp 进行双工检查 Silverlight 客户端的连接是否仍然有效?

发布于 2024-10-02 14:58:11 字数 1209 浏览 0 评论 0原文

我正在使用 net.tcp 和 netTcpBinding 组合一个 WCF 服务,以便与我的 Silverlight 客户端进行双工通信。我从 Silverlight 应用程序调用该服务,该服务调用另一个服务器,并向其传递 WCF 服务类中的回调方法。远程服务器会多次回调,每次回调时,WCF 服务都会使用回调通道将数据发送到 Silverlight 客户端。大多数时候这一切都运行良好。

如果用户发出很大的请求,在大量回调已经工作后我会收到 TimeoutException。 (显然,在其他地方还需要做一些工作来防止这种情况发生,但我想首先增强服务。)

我希望在尝试回调之前进行某种“if (client.ConnectionState == failed)”检查到 Silverlight 客户端,但我似乎找不到保存连接状态的对象。有吗?我是否从错误的角度处理这个问题?

这是我第一次涉足 net.tcp 和 duplex 服务。我刚搬家,我的 WCF 圣经还在盒子里。某处。 :-) 所以,我无法进行通常的背景阅读。

任何指点将不胜感激。这是一些裸代码,以防我的描述太糊涂:

    private IActiveDirectoryClient client;
    private AsyncSearchRunner runner;

    public void Search(Request request)
    {
        this.client = OperationContext.Current.GetCallbackChannel<IActiveDirectoryClient>();

        runner = new AsyncSearchRunner();
        runner.Run(request.SearchRoot, request.SearchFilter, request.PageSize, 
            System.DirectoryServices.Protocols.SearchScope.Subtree, SendObjects);
    }

    private void SendObjects(List<DirectoryObject> items)
    {
        Response response = new Response();
        response.DirectoryObjects = items.ToArray();

        client.SendResponse(response);
    }

I'm putting together a WCF service using net.tcp and netTcpBinding to get duplex comms with my Silverlight client. I call into the service from the Silverlight app and the service calls out to another server, passing it a callback method in the WCF service class. The remote server calls back several times and each time it does, the WCF service uses the callbackchannel to send the data to the Silverlight client. It all works nicely most of the time.

If the user puts in a big request, I get a TimeoutException after a large number of callbacks have already worked. (Clearly, there's some work to do elsewhere to prevent this but I'd like to robustify the service, first.)

I was expecting to do some kind of 'if (client.ConnectionState == faulted)' check before trying to call back to the Silverlight client but I can't seem to find the object that holds the state of the connection. Is there one? Am I approaching this from the wrong side?

This is my first venture into a service net.tcp and duplex. I just moved house and my WCF bible is still in a box. Somewhere. :-) So, I can't do my usual background reading.

Any pointers would be gratefully received. Here's some bare code in case my description is too soupy:

    private IActiveDirectoryClient client;
    private AsyncSearchRunner runner;

    public void Search(Request request)
    {
        this.client = OperationContext.Current.GetCallbackChannel<IActiveDirectoryClient>();

        runner = new AsyncSearchRunner();
        runner.Run(request.SearchRoot, request.SearchFilter, request.PageSize, 
            System.DirectoryServices.Protocols.SearchScope.Subtree, SendObjects);
    }

    private void SendObjects(List<DirectoryObject> items)
    {
        Response response = new Response();
        response.DirectoryObjects = items.ToArray();

        client.SendResponse(response);
    }

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寄风 2024-10-09 14:58:11

是的,在 ClientBase 类中定义了一个 State 属性(所有代理类均派生自 ClientBase )。

有一些代理包装器可以处理连接的故障状态并根据需要重新建立连接。 Google 搜索“wcf 代理包装器”。

如果您使用某种 ServiceLocator 模式,您还可以自制一些东西。

Yes, there is a State property that is defined in the ClientBase<> class (all the proxy classes are derived from ClientBase<>).

There are some proxy wrappers out there that handle fault states of the connection and re-establish connections as needed. Google for "wcf proxy wrapper".

You can also home-brew something if you use some kind of ServiceLocator pattern.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文