wcf全面解析proj1企业内部交流平台.ppt_第1页
wcf全面解析proj1企业内部交流平台.ppt_第2页
wcf全面解析proj1企业内部交流平台.ppt_第3页
wcf全面解析proj1企业内部交流平台.ppt_第4页
wcf全面解析proj1企业内部交流平台.ppt_第5页
已阅读5页,还剩33页未读, 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

BF TECH4 0DNET软件开发工程师高薪就业品牌课程版权所有 北风网 使用WCF搭建企业通用架构讲师 石曼迪 项目案例1 企业内部交流平台 目录 内部交流平台需求内部交流平台技术选型内部交流平台设计内部交流平台实现内部交流平台演示内部交流平台项目总结 目标 熟悉WCF开发了解WPF开发了解通信原理 项目成果展示 项目成果展示 内部交流平台背景 衡量沟通效果的四个指标 方便性 及时性 有效性 可追溯性 先看一下我们对各种沟通方式的对比分析 面对面沟通 电话沟通 Email电子邮件 IM即时通讯 内部交流平台背景 我们需要沟通 我们能实现及时沟通 内部交流平台技术选型 内部交流平台技术选型 套接字编程 不要复杂的配置 不要开发成本高 不要维护性能差 不要平台兼容性不好 不要扩展性差 不要协议单一 不要那我们要啥 WCF能够满足这些要求 内部交流平台设计 采用WCF服务端 客户端方式 通过TCP IP通信协议 采用WPF界面开发 设备无关性 采用ServiceThrottlingBehavior高性能配置建议 内部交流平台实现 服务端 采用HTTP和TCP IP两种协议进行通讯采用WPF应用程序作为宿主端口IP自配置 内部交流平台实现 服务端 类图 内部交流平台实现 服务端 类图 内部交流平台实现 服务端 界面实现 LocalIP ListenPort StopStartStatusChatService 内部交流平台实现 服务端 引用程序集 内部交流平台实现 服务端 定义一个服务 设置文件传输参数 UrihttpAdrs newUri http textBoxIP Text ToString int Parse textBoxPort Text ToString 1 ToString WPFHost Uri baseAdresses tcpAdrs httpAdrs host newServiceHost typeof ServiceAssembly ChatService baseAdresses NetTcpBindingtcpBinding newNetTcpBinding SecurityMode None true 设置文件传输最大为64MBtcpBinding MaxBufferPoolSize int 67108864 tcpBinding MaxBufferSize 67108864 tcpBinding MaxReceivedMessageSize int 67108864 tcpBinding TransferMode TransferMode Buffered tcpBinding ReaderQuotas MaxArrayLength 67108864 tcpBinding ReaderQuotas MaxBytesPerRead 67108864 tcpBinding ReaderQuotas MaxStringContentLength 67108864 内部交流平台实现 服务端 打开优化配置 设置保持连接 ServiceThrottlingBehaviorthrottle throttle host Description Behaviors Find if throttle null throttle newServiceThrottlingBehavior throttle MaxConcurrentCalls 100 throttle MaxConcurrentSessions 100 host Description Behaviors Add throttle 保持连接20hours tcpBinding ReceiveTimeout newTimeSpan 20 0 0 tcpBinding ReliableSession Enabled true tcpBinding ReliableSession InactivityTimeout newTimeSpan 20 0 10 host AddServiceEndpoint typeof ServiceAssembly IChat tcpBinding tcp 内部交流平台实现 服务端 开启服务 try host Open catch Exceptionex labelStatus Content ex Message ToString finally if host State CommunicationState Opened labelStatus Content Opened buttonStop IsEnabled true 内部交流平台实现 服务端 测试服务 http localhost 7998 WPFHost 内部交流平台实现 服务端 配置文件 内部交流平台实现 客户端 采用WPF应用程序作为客户端表现 增加头像和文件传输 内部交流平台实现 客户端 增加服务引用net tcp localhost 7996 WPFHost mex 内部交流平台实现 客户端 界面实现 内部交流平台实现 客户端 定义事件 定义客户端集合 this Loaded newRoutedEventHandler Window1 Loaded chatListBoxNames SelectionChanged newSelectionChangedEventHandler chatListBoxNames SelectionChanged chatTxtBoxType KeyDown newKeyEventHandler chatTxtBoxType KeyDown chatTxtBoxType KeyUp newKeyEventHandler chatTxtBoxType KeyUp DictionaryOnlineClients newDictionary 内部交流平台实现 客户端 定义状态判断 if proxy null switch this proxy State caseCommunicationState Closed proxy null loginButtonConnect IsEnabled true break caseCommunicationState Closing break caseCommunicationState Created break caseCommunicationState Faulted proxy Abort break caseCommunicationState Opened ShowLogin false break caseCommunicationState Opening break 内部交流平台实现 客户端 建立客户端连接 stringservicePath proxy Endpoint Address proxy Open proxy InnerDuplexChannel Faulted newEventHandler InnerDuplexChannel Faulted proxy InnerDuplexChannel Opened newEventHandler InnerDuplexChannel Opened proxy InnerDuplexChannel Closed newEventHandler InnerDuplexChannel Closed proxy ConnectAsync this localClient proxy ConnectCompleted newEventHandler proxy ConnectCompleted 内部交流平台实现 客户端 消息发送 if bool chatCheckBoxWhisper IsChecked if this receiver null proxy WhisperAsync msg this receiver chatTxtBoxType Text chatTxtBoxType Focus else proxy SayAsync msg chatTxtBoxType Text 内部交流平台实现 客户端 添加头像 Dictionaryimages newDictionary inti 0 foreach StreamstrminpicsStrm PngBitmapDecoderdecoder newPngBitmapDecoder strm BitmapCreateOptions PreservePixelFormat BitmapCacheOption Default BitmapSourcebitmap decoder Frames 0 asBitmapSource Imageimg newImage img Source bitmap img Stretch Stretch UniformToFill images Add i img i strm Close returnimages 内部交流平台实现 客户端 文件发送 OpenFileDialogfileDialog newOpenFileDialog fileDialog Multiselect false strm fileDialog OpenFile if strm null byte buffer newbyte int strm Length inti strm Read buffer 0 buffer Length if i 0 SVC FileMessagefMsg newFileMessage fMsg FileName fileDialog SafeFileName fMsg Sender this localClient Name fMsg Data buffer proxy SendFileAsync fMsg this receiver proxy SendFileCompleted newEventHandler proxy SendFileCompleted chatLabelSendFileStatus Content Sending 内部交流平台实现 客户端 文件接收 try FileStreamfileStrm newFileStream rcvFilesPath fileMsg FileName FileMode Create FileAccess ReadWrite fileStrm Write fileMsg Data 0 fileMsg Data Length chatLabelSendFileStatus Content Receivedfile fileMsg FileName catch Exceptionex chatLabelSendFileStatus Content ex Message ToString 内部交流平台实现 客户端 用户登录和注销 publicvoidUserJoin WPFClient SVC Clientclient ListBoxItemitem MakeItem client AvatarID client Name joinedchat chatListBoxMsgs Items Add item ScrollViewersv FindVisualChild chatListBoxMsgs sv LineDown publicvoidUserLeave WPFClient SVC Clientclient ListBoxItemitem MakeItem client AvatarID client Name leftchat chatListBoxMsgs Items Add item ScrollViewersv FindVisualChild chatListBoxMsgs sv LineDown 内部交流平台实现 客户端 配置文件 内部交流平台演示 内部交流平台项目总结 为什么要使用net tcp绑定为了更好地实现

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论