Silverlight 和推送通知 [英] Silverlight and push notifications

查看:38
本文介绍了Silverlight 和推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为远程仪器创建 Silverlight 2 用户界面.不同地点有两个并发用户与仪器交互(仪器操作员和远程科学家),还有任意数量的观察者用户不与其交互,只是观看.但是,每当两个活跃用户之一更改某些内容时,这些更改必须立即反映在所有用户的 UI 中,例如平移或缩放图像或注释或选择图像的一部分,将项目添加到列表框中显示的集合中.在客户端中,我使用可观察的集合,这些集合很容易反映该用户所做的更改,但很难看到另一个用户所做的更改.我可以轮询每个客户端的更改,但推送通知之类的内容会更好.我已经广泛搜索了示例,但没有找到任何我需要的东西.Silverlight 与 WCF 服务交互存在各种安全问题,这意味着许多潜在示例无法正常工作.我在这个项目上基本上没有时间了,需要快速帮助.有没有人对一个合适的简单例子有任何建议来说明如何做到这一点?我是一名经验丰富的开发人员,但不得不自学 Silverlight 和 WCF 服务,我所在的地区没有人了解这些.即使我已经完成了相当多的 ASP.NET 工作,我也不是网络/Javascript 专家.谢谢.

I am creating a Silverlight 2 user interface to a remote instrument. There are two concurrent users at different sites interacting with the instrument (operator at the instrument and remote scientist) and any number of observer users not interacting with it, just watching. However, whenever one of the two active users changes something these changes must be immediately reflected in the UIs of all users, e.g. panning or zooming an image or annotating or selecting part of an image, adding items to a collection displayed in a listbox. Within the client I use observable collections which easily reflect changes made by that user, but it is harder seeing changes made by another user. I can poll for changes from each client but something like push notifications would be better. I have extensively Googled for examples but not found anything which is quite what I need. There are all sorts of security issues with Silverlight interacting with WCF services which mean many potential examples just don't work. I have essentially run out of time on this project and need help fast. Does anyone have any suggestion of a suitable simple example which illustrates how to do this? I am an experienced developer but have had to teach myself Silverlight and WCF services and there is noone in my area who knows anything about these. Even tho' I have done a fair amount of ASP.NET work I am not a web/Javascript guru. Thanks.

推荐答案

使用新的 WCF PollingDuplexHttpBinding 支持在 Silverlight 2 中支持推送通知.Silverlight SDK 安装了两个程序集 (一个用于 Silverlight 应用,一个用于 WCF 服务器).

Push notification is supported in Silverlight 2 using the new WCF PollingDuplexHttpBinding support. There are two assemblies installed with the Silverlight SDK (one for Silverlight app one for WCF server).

我有一个一些博客帖子和一个完整的示例应用程序,演示了如何从自托管 WCF 服务的控制台应用程序服务器向连接的客户端推送" Stock 更新.它还展示了每个客户端如何针对股票添加注释并将这些注释同步(从服务器推送)到所有其他连接的客户端.

I have a few blog posts and a full sample application that demonstrate how to 'push' Stock updates from a Console Application server that self-hosts a WCF service to connected clients. It also shows how each client can add notes against a Stock and have those notes synchronized (pushed from server) to all other connected clients.

示例的最新版本(第 4 部分)展示了如何使用两个服务器端点在 Silverlight 和 WPF 客户端之间同步推送更新,如下所示:

The latest version of the sample (Part 4) shows how to synchronize pushed updates between both Silverlight and WPF clients using two server endpoints as follows:

using System;
using System.ServiceModel;
using System.ServiceModel.Description;

namespace StockServer
{
    public class StockServiceHost : ServiceHost
    {
        public StockServiceHost(object singletonInstance, params Uri[] baseAddresses)
            : base(singletonInstance, baseAddresses)
        {
        }

        public StockServiceHost(Type serviceType, params Uri[] baseAddresses)
            : base(serviceType, baseAddresses)
        {
        }

        protected override void InitializeRuntime()
        {
            this.AddServiceEndpoint(
                typeof(IPolicyProvider),
                new WebHttpBinding(),
                new Uri("http://localhost:10201/")).Behaviors.Add(new WebHttpBehavior());

            this.AddServiceEndpoint(
                typeof(IStockService),
                new PollingDuplexHttpBinding(),
                new Uri("http://localhost:10201/SilverlightStockService"));

            this.AddServiceEndpoint(
                typeof(IStockService),
                new WSDualHttpBinding(WSDualHttpSecurityMode.None),
                new Uri("http://localhost:10201/WpfStockService"));

            base.InitializeRuntime();
        }
    }
}

WPF 客户端连接到 WSDualHttpBinding 端点,Silverlight 客户端连接到同一 WCF 服务的 PollingDuplexHttpBinding 端点.该应用还展示了如何处理 Silverlight 客户端访问策略要求.

WPF clients connect to the WSDualHttpBinding endpoint and Silverlight clients connect to the PollingDuplexHttpBinding endpoint of the same WCF service. The app also shows how to handle the Silverlight client access policy requirements.

客户端(Silverlight 或 WPF)可以在其 UI 中针对股票添加注释,这些注释会传播回服务器以推送到所有其他客户端.这展示了双向通信,并有望执行您的应用所需的所有必要通信.

Clients (Silverlight or WPF) can add notes against a Stock in their UI and these notes propagate back to the server to be pushed to all other clients. This demonstrates communication in either direction and hopefully performs all of the necessary communication required for your app.

您可以看到 在此处运行的演示应用程序.

这篇关于Silverlight 和推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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