要考慮的一種可能性是將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的屏幕截圖。
謝謝你,我打算做一個silverlight客戶端我迫不及待想去那個部分:) – 2009-02-03 05:57:19