使用用WCF中的双工(Duplex)模式将广告图片推送到每个Winform客户端机子上
2014-02-07 15:32
411 查看
参考资料地址:/article/6161563.html
代码实现:
WCF宿主(服务端)
View Code
Demo下载地址:http://files.cnblogs.com/wgx0428/wcf%E6%8E%A8%E9%80%81%E4%B8%8E%E5%B9%BF%E6%92%AD.zip
代码实现:
WCF宿主(服务端)
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; using System.ServiceModel; namespace WinFormClient { public partial class FormClient : Form { public FormClient() { InitializeComponent(); this.Text = "当前客户端编号为:"+DateTime.Now.ToString("yyyyMMddHHmmss"); try { Console.WriteLine("create object..."); CallBack back = new CallBack(); InstanceContext context = new InstanceContext(back); ServiceReference1.ServicesClient client = new ServiceReference1.ServicesClient(context); Console.WriteLine("regist....."); back.showPic += new CallBack.ShowPic(ShowPicMethod); client.Register(); Console.WriteLine("aucceeded"); //this.ReceivePic.Image = back.Pic; } catch (Exception ex) { Console.WriteLine(ex.Message); } } public void ShowPicMethod(Bitmap bitmap) { this.ReceivePic.Image = bitmap; } } public class CallBack : ServiceReference1.IServicesCallback { public delegate void ShowPic(Bitmap bitmap); public event ShowPic showPic; #region IServicesCallback 成员 public void SendMessage(string Message) { Console.WriteLine("[ClientTime{0:HHmmss}]Service Broadcast:{1}", DateTime.Now, Message); } public void SendPicStream(ServiceReference1.MessageEntity messageEntity) { this.showPic(GetImage(messageEntity.PicStream)); } #endregion #region 将图片二进制流转换为图片 public static Bitmap GetImage(byte[] ImageDatas) { try { //如果是字符串的话 //byte[] resultBytes = Convert.FromBase64String(ImageDatas); using (MemoryStream ImageMS = new MemoryStream()) { ImageMS.Write(ImageDatas, 0, ImageDatas.Length); Bitmap resultBitmap = new Bitmap(ImageMS); return resultBitmap; } } catch { return null; } } #endregion } }
View Code
Demo下载地址:http://files.cnblogs.com/wgx0428/wcf%E6%8E%A8%E9%80%81%E4%B8%8E%E5%B9%BF%E6%92%AD.zip
相关文章推荐
- WCF----最简单的winform客户端回调服务端WCFDemo下载,双工模式,IIS 6.0
- WCF双工模式服务端回调客户端
- WCF消息安全模式之自定义用户名密码:Message CustomUserNamePassword wsHttpBinding 使用Windows Services宿主以及客户端免证书验证
- Winform客户端引用WCF客户端后,部分类无法正常使用
- 利用 WCF duplex Service 【推送】数据到Siliverlight客户端 的双向通讯例子
- 利用WCF的Duplex服务向Winform程序推送消息
- Winform客户端引用WCF客户端后,部分类无法正常使用
- WCF初探-5:WCF消息交换模式之双工通讯(Duplex)
- WCF----双工模式服务端回调客户端方法时无响应,“发送到 http://***/User.svc 的请求操作在配置的超时内未收到回复”
- WCF服务创建与使用(双工模式)
- [SDK2.2]Windows Azure Storage (16) 使用WCF服务,将本地图片上传至Azure Storage (上) 客户端代码
- WCF消息交换模式之双工通讯(Duplex)
- 使用wcf的双工模式做的一个控制台聊天app
- WCF系列教程之消息交换模式之双工通讯(Duplex)
- 利用 WCF duplex Service 【推送】数据到Siliverlight客户端 的双向通讯例子
- 利用WCF的Duplex服务向Winform程序推送消息
- 利用WCF的Duplex服务向Winform程序推送消息
- DuplexChannelFactory 使用WCF创建订阅发布程序时,客户端点击订阅时出现“ChannelFactory.Endpoint 上的地址属性为空。ChannelFactory 的终结点必
- 使用WCF实现服务器向客户端的信息推送
- 开源框架Pushlet入门,使用Pushlet将消息从服务器端推送到客户端