




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、BF-TECH 4.0 DNET 软件开发工程师高薪就业品牌课程版权所有:北风网,使用WCF搭建企业通用架构讲师:石曼迪,项目案例1:企业内部交流平台,目录,内部交流平台需求 内部交流平台技术选型 内部交流平台设计 内部交流平台实现 内部交流平台演示 内部交流平台项目总结,目标,熟悉WCF开发 了解WPF开发 了解通信原理,项目成果展示,项目成果展示,内部交流平台背景,衡量沟通效果的四个指标:方便性、及时性、有效性、可追溯性。先看一下我们对各种沟通方式的对比分析: 面对面沟通; 电话沟通; Email电子邮件; IM即时通讯;,内部交流平台背景,我们需要沟通 我们能实现及时沟通,内部交流平台技
2、术选型,内部交流平台技术选型,套接字编程? 不要 复杂的配置? 不要 开发成本高? 不要 维护性能差? 不要 平台兼容性不好? 不要 扩展性差? 不要 协议单一? 不要 那我们要啥? WCF能够满足这些要求!,内部交流平台设计,采用WCF服务端+客户端方式; 通过TCP/IP通信协议; 采用WPF界面开发(设备无关性); 采用ServiceThrottlingBehavior高性能配置建议;,内部交流平台实现:服务端,采用HTTP和TCP/IP两种协议进行通讯 采用WPF应用程序作为宿主 端口IP自配置,内部交流平台实现:服务端,类图,内部交流平台实现:服务端,类图,内部交流平台实现:服务端,
3、界面实现,Local IP: Listen Port: Stop Start Status Chat Service,内部交流平台实现:服务端,引用程序集,内部交流平台实现:服务端,定义一个服务: 设置文件传输参数,Uri httpAdrs = new Uri(http:/ + textBoxIP.Text.ToString() + : + (int.Parse(textBoxPort.Text.ToString() + 1).ToString() + /WPFHost/); Uri baseAdresses = tcpAdrs, httpAdrs ; host = new ServiceHo
4、st(typeof(ServiceAssembly.ChatService), baseAdresses);,NetTcpBinding tcpBinding = new NetTcpBinding(SecurityMode.None, true); /设置文件传输最大为 64 MB tcpBinding.MaxBufferPoolSize = (int)67108864; tcpBinding.MaxBufferSize = 67108864; tcpBinding.MaxReceivedMessageSize = (int)67108864; tcpBinding.TransferMode
5、 = TransferMode.Buffered; tcpBinding.ReaderQuotas.MaxArrayLength = 67108864; tcpBinding.ReaderQuotas.MaxBytesPerRead = 67108864; tcpBinding.ReaderQuotas.MaxStringContentLength = 67108864;,内部交流平台实现:服务端,打开优化配置: 设置保持连接,ServiceThrottlingBehavior throttle; throttle = host.Description.Behaviors.Find(); if
6、 (throttle = null) throttle = new ServiceThrottlingBehavior(); throttle.MaxConcurrentCalls = 100; throttle.MaxConcurrentSessions = 100; host.Description.Behaviors.Add(throttle); ,/保持连接 20 hours. tcpBinding.ReceiveTimeout = new TimeSpan(20, 0, 0); tcpBinding.ReliableSession.Enabled = true; tcpBinding
7、.ReliableSession.InactivityTimeout = new TimeSpan(20, 0, 10); host.AddServiceEndpoint(typeof(ServiceAssembly.IChat), tcpBinding, tcp);,内部交流平台实现:服务端,开启服务:,try host.Open(); catch (Exception ex) labelStatus.Content = ex.Message.ToString(); finally if (host.State = CommunicationState.Opened) labelStatus
8、.Content = Opened; buttonStop.IsEnabled = true;,内部交流平台实现:服务端,测试服务:,http:/localhost:7998/WPFHost/,内部交流平台实现:服务端,配置文件:, ,内部交流平台实现:客户端,采用WPF应用程序作为客户端表现: 增加头像和文件传输,内部交流平台实现:客户端,增加服务引用 net.tcp:/localhost:7996/WPFHost/mex,内部交流平台实现:客户端,界面实现:, ,内部交流平台实现:客户端,定义事件: 定义客户端集合,this.Loaded += new RoutedEventHandler
9、(Window1_Loaded); chatListBoxNames.SelectionChanged += new SelectionChangedEventHandler(chatListBoxNames_SelectionChanged); chatTxtBoxType.KeyDown += new KeyEventHandler(chatTxtBoxType_KeyDown); chatTxtBoxType.KeyUp += new KeyEventHandler(chatTxtBoxType_KeyUp);,Dictionary OnlineClients = new Diction
10、ary();,内部交流平台实现:客户端,定义状态判断:,if (proxy != null) switch (xy.State) case CommunicationState.Closed: proxy = null; loginButtonConnect.IsEnabled = true; break; case CommunicationState.Closing: break; case CommunicationState.Created: break; case CommunicationState.Faulted: proxy.Abort(); break; ca
11、se CommunicationState.Opened: ShowLogin(false); break; case CommunicationState.Opening: break;,内部交流平台实现:客户端,建立客户端连接:,string servicePath = . proxy.Endpoint.Address = . proxy.Open(); proxy.InnerDuplexChannel.Faulted += new EventHandler(InnerDuplexChannel_Faulted); proxy.InnerDuplexChannel.Opened += ne
12、w EventHandler(InnerDuplexChannel_Opened); proxy.InnerDuplexChannel.Closed += new EventHandler(InnerDuplexChannel_Closed); proxy.ConnectAsync(this.localClient); proxy.ConnectCompleted += new EventHandler(proxy_ConnectCompleted);,内部交流平台实现:客户端,消息发送:,if (bool)chatCheckBoxWhisper.IsChecked) if (this.rec
13、eiver != null) proxy.WhisperAsync(msg, this.receiver); chatTxtBoxType.Text = ; chatTxtBoxType.Focus(); else proxy.SayAsync(msg); chatTxtBoxType.Text = ; ,内部交流平台实现:客户端,添加头像:,Dictionary images = new Dictionary(); int i = 0; foreach (Stream strm in picsStrm) PngBitmapDecoder decoder = new PngBitmapDeco
14、der(strm, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); BitmapSource bitmap = decoder.Frames0 as BitmapSource; Image img = new Image(); img.Source = bitmap; img.Stretch = Stretch.UniformToFill; images.Add(i, img); i+; strm.Close(); return images;,内部交流平台实现:客户端,文件发送:,OpenFileDia
15、log fileDialog = new OpenFileDialog(); fileDialog.Multiselect = false; strm = fileDialog.OpenFile(); if (strm != null) byte buffer = new byte(int)strm.Length; int i = strm.Read(buffer, 0, buffer.Length); if (i 0) SVC.FileMessage fMsg = new FileMessage(); fMsg.FileName = fileDialog.SafeFileName; fMsg
16、.Sender = this.localClient.Name; fMsg.Data = buffer; proxy.SendFileAsync(fMsg, this.receiver); proxy.SendFileCompleted += new EventHandler(proxy_SendFileCompleted); chatLabelSendFileStatus.Content = Sending.; ,内部交流平台实现:客户端,文件接收:,try FileStream fileStrm = new FileStream(rcvFilesPath + fileMsg.FileNam
17、e, FileMode.Create, FileAccess.ReadWrite); fileStrm.Write(fileMsg.Data, 0, fileMsg.Data.Length); chatLabelSendFileStatus.Content = Received file, + fileMsg.FileName; catch (Exception ex) chatLabelSendFileStatus.Content = ex.Message.ToString(); ,内部交流平台实现:客户端,用户登录和注销:,public void UserJoin(WPFClient.SV
18、C.Client client) ListBoxItem item = MakeItem(client.AvatarID, - + client.Name + joined chat -); chatListBoxMsgs.Items.Add(item); ScrollViewer sv = FindVisualChild(chatListBoxMsgs); sv.LineDown(); ,public void UserLeave(WPFClient.SVC.Client client) ListBoxItem item = MakeItem(client.AvatarID, - + client.Name + left chat -); chatListBoxMsgs.Items.Add(item); ScrollViewer sv = FindVisualChild(chatListBoxMsgs); sv.LineDown(); ,内部交流平台实现:客户端,配置文件:, , ,内部交流平台演示,内部交流平台项目总结,为什么要使用 ne
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 嘉兴一中强基数学试卷
- 护士专升本的数学试卷
- 2025年传统食品行业智能化生产技术改造深度分析报告
- 在线职业技能认证平台2025年:智能制造领域人才认证研究
- 2022年果洛藏族自治州五年级语文第四单元考试试卷
- 2022年阜阳市一年级语文期中考试试卷(人教版)
- 聚焦2025年工业互联网平台边缘计算硬件架构性能提升策略报告
- 2025年度租赁住房合同押金退还流程范本
- 二零二五年度大件货物长途运输及临时停靠协议
- 2025年房产营销顾问全面服务协议
- 夜景照明课件
- 2023建设工程智慧消防系统技术规程
- 江苏省消防安全重点单位界定标准
- 成人癌性疼痛护理指南解读
- 经营指标培训PPT
- 空调公司管理制度
- 高中英语-高二英语试卷讲评教学课件设计
- 第十四讲 建设巩固国防和强大人民军队PPT习概论2023优化版教学课件
- 个体工商户诚信承诺书范本
- 证券从业资格证模拟题
- 《园林工程技术专业教学标准》调研报告 全市获奖
评论
0/150
提交评论