silverlight
发布时间:2022-05-04 发布网站:大佬教程 code.js-code.com
大佬教程收集整理的这篇文章主要介绍了稳扎稳打Silverlight(23) - 2.0通信之调用WCF的双向通信(Duplex Service),大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
概述
[索引页] [源码下载] 稳扎稳打Silverlight(23) - 2.0通信之调用WCF的双向通信(Duplex
servic
E) 作者: webabcd 介绍 Silverlight 2.0 调用 WCF 的双向通信服务(Duplex
servic
E) 。开发一个服务端主动向客服端发送股票信息的程序,首先客户端先向服务端发送需要监控的股票的股票代码,然后服务端在该股信息发生变化的时候将信
PollingDuplex
serviceHostFactory.cs
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.serviceModel;
using
System.serviceModel.ChAnnels;
using
System.serviceModel.Activation;
/* 以下部分摘自文档 */
//
服务 svc 文件的 Factory 要指定为此类
public
class
PollingDuplexserviceHostFactory : serviceHostFactoryBase
@H_944_1382@
{
public override serviceHostBase CreateserviceHost(String constructorString,
UrI[] baseAddresses)
{
return new PollingDuplexSimplexserviceHost(baseAddresses);
}
}
class
PollingDuplexSimplexserviceHost : serviceHost
{
public PollingDuplexSimplexserviceHost(params System.UrI[] addresses)
{
base.InitializeDescription(typeof(DuplexservicE), new UrischeR_605_11845@eKeyedCollection(addresses));
}
protected override void InitializeRuntime()
@H_990_1555@
{
// 配置 WCF 服务与 Silverlight 客户端之间的 Duplex 通信
// Silverlight 客户端定期轮询网络层上的服务,并检查回调信道上由服务端发送的所有新的消息
// 该服务会将回调信道上的由服务端发送的所有消息进行排队,并在客户端轮询服务时将这些消息传递到该客户端
PollingDuplexBindingElement pdbe = new PollingDuplexBindingElement()
@H_46_1618@
{
// ServerPollTimeout - 轮询超时时间
// InactivityTimeout - 服务端与客户端在此超时时间内无任何消息交换的情况下,服务会关闭其会话
ServerPollTimeout = TimeSpan.FromSeconds(3),
inactivityTimeout = TimeSpan.Fromminutes(1)
};
// 为服务契约(service contract)添加一个终结点(endpoint)
// Duplex 服务仅支持 Soap11
this.AddserviceEndpoint(
typeof(IDuplexservicE),
new CustomBinding(
pdbe,
new textmessageEncodingBindingElement(
messageVersion.soap11,
System.Text.Encoding.UTF8),
new httpTransportBindingElement()),
"");
base.InitializeRuntime();
}
}
Duplex
service.svc
<%
@H_616_1851@@ serviceHost Language="C#" Debugtrue serviceDuplexservice CodeBehind~/App_Code/Duplexservice.cs FactoryPollingDuplexserviceHostFactory
%>
大佬总结
以上是大佬教程为你收集整理的稳扎稳打Silverlight(23) - 2.0通信之调用WCF的双向通信(Duplex Service)全部内容,希望文章能够帮你解决稳扎稳打Silverlight(23) - 2.0通信之调用WCF的双向通信(Duplex Service)所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。