一种可能的考虑是将 Silverlight 2 应用程序作为 Web 用户导航到的 ASP.NET 页面的一部分。
此 Silverlight 应用程序可以利用 Silverlight 2 SDK 随附的 System.ServiceModel.PollingDuplex.dll 程序集 (one for Silverlight app one for WCF server) 中的 WCF 轮询双工支持。
我有一个few blog posts and a sample application,它演示了如何从控制台应用程序“推送”库存更新,该控制台应用程序自托管具有两个端点的 WCF 服务,如下所示:
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 客户端访问策略要求。
客户端(Silverlight 或 WPF)可以在其 UI 中针对股票添加注释,这些注释传播回服务器以推送到所有其他客户端。这演示了双向通信,并有望执行聊天应用程序所需的大部分必要通信。
你可以看到demo application running here的截图。