【WCF】VSTO Host WCF Web Api
来源:互联网 发布:传奇霸业最新魂珠数据 编辑:程序博客网 时间:2024/05/29 11:11
最近突发奇想,在PPT运行发布一个WebApi,这样通过手机或者浏览器就能控制此PPT播放。于是尝试了下用 WCF 里的 WebServiceHost 寄宿在VSTO的对象上。
因此有了下面这个类:
SlideShowServiceHost.cs
ThisAddIn.cs
因此有了下面这个类:
SlideShowServiceHost.cs
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.ServiceModel;using System.ServiceModel.Description;using System.ServiceModel.Web;using System.Net;namespace SlideShow{ public class SlideShowServiceHost { private static WebServiceHost _host; public static void Open() { var ipAddressList = Dns.GetHostEntry(Dns.GetHostName()).AddressList; var ipFirst = ipAddressList.First(ip => ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork).ToString(); _host = new WebServiceHost(typeof(SlideShowService), new Uri(string.Format("http://{0}:81", ipFirst))); _host.Open(); } public static void Close() { if (_host != null) { _host.Close(); ((IDisposable)_host).Dispose(); } } }}这个 SlideShowServiceHost 在VSTO启动Application时加载,运行PPT时Open:
ThisAddIn.cs
void Application_SlideShowBegin(PowerPoint.SlideShowWindow Wn){ var ret = MessageBox.Show("Begin SlideShowServer?", "SlideShow", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (ret != DialogResult.OK) return; SlideShowServiceHost.Open(); ...}
void Application_SlideShowEnd(PowerPoint.Presentation Pres){ MessageBox.Show("SlideShow Server ShutDown."); SlideShowServiceHost.Close();}OK, 很简单吧。
- 【WCF】VSTO Host WCF Web Api
- WCF 、Web API 、 WCF REST 和 Web Service 的区别
- WCF、 Web API、 WCF REST 和 Web Service 的区别
- WCF 、Web API 、 WCF REST 和 Web Service 的区别
- WCF ,Web API , WCF REST 和 Web Service 的区别
- WCF: Host、Client、MetadataExchage
- WCF Notes4(Host)
- WCF: Host、Client、MetadataExchage
- self host WCF + ssl
- WCF Web API 轻松实现 REST
- WCF和ASP.NET Web API
- WCF与Web API 区别(应用场景)
- WCF与Web API 区别(应用场景)
- WCF和WEB API的区别
- VSTO+WinForm+WebService+WCF+WPF示例
- WCF Service Host和WCF Test Client
- 【WCF】自动加载WCF Library (IIS Host)
- Wcf
- C#入门经典学习9-定义类
- 用vba写的自动添加源文件的宏,可以用来方便添加c++源文件的头注释
- 使用Condition控制线程协调工作
- C++学习小结
- 找回 Mac OS X Lion 10.7中被隐藏的资源库(Library)
- 【WCF】VSTO Host WCF Web Api
- Xcode4 修改公司名称
- C语言结构体对齐问题
- Pidgin插件Hello world的代码分析
- Drupal 如何访问一个模块
- 【OpenGL4.0】GLSL渲染语言入门与VBO、VAO使用:绘制一个三角形
- 6月3日,下了一整天的小雨
- 关于键盘触发事件和屏幕触发事件的问题
- 太宗皇帝的长孙皇后