WCF 服务如何向其客户端引发事件? [英] How can a WCF Service Raise Events to its Clients?

查看:30
本文介绍了WCF 服务如何向其客户端引发事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道 WCF 中是否有事件处理方式.我在 WCF 中遇到过回调,但我想在 WCF 中进行事件处理.

I want to know is there way of Event Handling in WCF. I came across Callbacks in WCF, but i want to do Event Handling in WCF.

我的要求就像我想向特定客户端引发事件,而不是向所有在 WCF 中使用事件处理的客户端引发事件,而且我还想维护会话.

My requirement is like i want to raise event to particular clients not to all the clients using Event Handling in WCF and i also want to maintain session.

我在 WCF 中看到过发布者/订阅者模型,它处理回调,但是这个模型发布给所有订阅的客户,但我只想发布给选定的客户.

I have seen Publisher/Subscriber model in WCF which deals with Callback , but this model publish to all the clients who have subscribed but i want to publish only to selected clients.

我认为可以使用 WCF 中的事件来完成.

I think that can be done using Events in WCF.

客户端:

public class Callbacks : IServiceCallback
{
    public void CallToMyClient(string name)
    {
        this.CallToMyClient(name);  

    }
}

protected void Page_Load(object sender, EventArgs e)
{
    Callbacks callback = new Callbacks();            
    ServiceClient client = new ServiceClient(new InstanceContext(callback));        

    client.SubscribeClient();
    client.DoSomeWork(); 
}

推荐答案

您不能使用事件.您可以使用回调来模拟事件.

You cannot use events. You can use callbacks to simulate events.

这篇关于WCF 服务如何向其客户端引发事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆