当前位置: 首页 > news >正文

企业网站尺寸学网站建设 去那里

企业网站尺寸,学网站建设 去那里,轻松seo优化排名 快排,厦门做返利网站的公司目录 引言 1. 创建一个新的Windows服务项目 2. 添加WCF服务 2.1 添加服务接口和实现 2.2 添加服务配置 3. 实现Windows服务 3.1 修改Service1类 3.2 在项目中添加ServiceInstaller 4. 安装和运行Windows服务 4.1 编译项目 4.2 使用InstallUtil.exe安装服务 …目录 引言         1. 创建一个新的Windows服务项目 2. 添加WCF服务 2.1 添加服务接口和实现 2.2 添加服务配置 3. 实现Windows服务 3.1 修改Service1类 3.2 在项目中添加ServiceInstaller 4. 安装和运行Windows服务 4.1 编译项目 4.2 使用InstallUtil.exe安装服务 4.3 启动服务 5. 测试WCF服务 5.1 添加客户端应用程序 5.2 添加服务引用 5.3 调用服务 6. 卸载Windows服务 引言         我们利用C#可以快速开发各种后端服务如常见的windows服务、WCF 服务、WebService服务、WebApi等上一篇文章介绍了简单WCF服务的实现本文将详细讲解如何基于 C# 和 .NET Framework 4.0 将 WCF服务和宿主项目合并到同一个项目中并将其安装为Windows服务确保每个步骤都清晰且易于理解和掌握。 以下是详细的步骤 1. 创建一个新的Windows服务项目 打开Visual Studio创建一个新的项目。选择 Windows Service 项目类型命名为 WcfWindowsService。 2. 添加WCF服务 2.1 添加服务接口和实现 在项目中添加两个类IService1.cs 和 Service1.cs。 IService1.cs: using System.ServiceModel;namespace WcfWindowsService {[ServiceContract]public interface IService1{[OperationContract]string GetData(int value);} }Service1.cs: namespace WcfWindowsService {public class Service1 : IService1{public string GetData(int value){return $You entered: {value};}} }2.2 添加服务配置 在项目中添加一个 App.config 文件并添加以下配置 configurationsystem.serviceModelservicesservice nameWcfWindowsService.Service1endpoint address bindingbasicHttpBinding contractWcfWindowsService.IService1 /hostbaseAddressesadd baseAddresshttp://localhost:8733/Design_Time_Addresses/WcfWindowsService/Service1/ //baseAddresses/host/service/servicesbehaviorsserviceBehaviorsbehaviorserviceMetadata httpGetEnabledTrue /serviceDebug includeExceptionDetailInFaultsFalse //behavior/serviceBehaviors/behaviors/system.serviceModel /configuration3. 实现Windows服务 3.1 修改Service1类 在 Service1.cs 文件中创建一个新的类 WcfService继承自 ServiceBase 类 using System; using System.ServiceModel; using System.ServiceProcess;namespace WcfWindowsService {public partial class WcfService : ServiceBase{public ServiceHost serviceHost null;public WcfService(){InitializeComponent();}protected override void OnStart(string[] args){if (serviceHost ! null){serviceHost.Close();}serviceHost new ServiceHost(typeof(Service1));serviceHost.Open();}protected override void OnStop(){if (serviceHost ! null){serviceHost.Close();serviceHost null;}}} }3.2 在项目中添加ServiceInstaller 右键点击项目选择 Add - New Item。选择 Component Class命名为 ProjectInstaller.cs。 在 ProjectInstaller.cs 中实现服务安装 using System.ComponentModel; using System.Configuration.Install; using System.ServiceProcess;namespace WcfWindowsService {[RunInstaller(true)]public partial class ProjectInstaller : Installer{private ServiceProcessInstaller processInstaller;private ServiceInstaller serviceInstaller;public ProjectInstaller(){processInstaller new ServiceProcessInstaller();serviceInstaller new ServiceInstaller();// 设置服务使用的账号类型processInstaller.Account ServiceAccount.LocalSystem;// 设置服务信息serviceInstaller.ServiceName WcfWindowsService;serviceInstaller.DisplayName WCF Windows Service;serviceInstaller.StartType ServiceStartMode.Manual;Installers.Add(processInstaller);Installers.Add(serviceInstaller);}} }4. 安装和运行Windows服务 4.1 编译项目 确保项目没有错误然后编译项目。 4.2 使用InstallUtil.exe安装服务 打开管理员权限的命令提示符导航到编译输出目录通常是bin\Debug或bin\Release并运行以下命令以安装服务 installutil WcfWindowsService.exe 4.3 启动服务 打开 Services 管理器按下WinR输入 services.msc 后回车。找到名为 WcfWindowsService 的服务。右键点击服务选择 Start 启动服务。 5. 测试WCF服务 5.1 添加客户端应用程序 创建一个新的 Console Application 项目来测试服务命名为 WcfClient。 5.2 添加服务引用 在客户端项目中右键点击项目选择 Add Service Reference输入服务地址如 http://localhost:8733/Design_Time_Addresses/WcfWindowsService/Service1/然后点击 Go 和 OK。 5.3 调用服务 在客户端的 Program.cs 中调用服务 using System;namespace WcfClient {class Program{static void Main(string[] args){var client new ServiceReference1.Service1Client();string result client.GetData(42);Console.WriteLine(result);client.Close();}} }6. 卸载Windows服务 如果不再需要服务可以卸载 installutil /u WcfWindowsService.exe通过这些步骤您可以将WCF服务和宿主项目合并到同一个项目中并将其安装为Windows服务。这样可以实现WCF服务的长期运行并通过Windows服务管理器来管理服务的生命周期。
http://www.hkea.cn/news/14406421/

相关文章:

  • 怎么合作做网站wordpress防止篡改文件linux
  • 毕业设计做网站怎样做特别一点网站制作商业模式
  • 汝南县网站建设网站备案帐号是什么
  • 遵义网站建设托管公司网站 动态内容加速
  • 电脑宽带网站东莞昨天发生的重大新闻
  • 网站地图页面设计网站开发 外包空心
  • 用vs2012怎么做网站wordpress+广告联盟
  • 网页界面设计的主要内容宁波seo外包方案
  • 世界各国o2o响应式网站邢台做wap网站的地方
  • 响应式全屏网站惠州seo外包平台
  • 网站推广员是什么怎么制作游戏u盘
  • 网站改标题装饰公司营销型网站
  • 网站治做啊app先做网站还是先解析
  • 朝阳区建网站公司有帮云旅游系统网站开发的背景
  • 网站开发实战成都专业做游戏网站
  • 网页设计图片轮播网站专题优化
  • 百度网站官网怎么做国外印花图案设计网站
  • 甘肃省建设厅官方网站信息网如何添加网站代码
  • 网站有哪些备案奇胜网络 邯郸网站建设
  • 建立网站坐等访问者发现什么网站都能进的浏览器
  • 福州网站制作哪里好百度搜索引擎优化的推广计划
  • 按城市亭湖建设局网站民治做网站哪家便宜
  • 深圳做网页的网站提高wordpress访问速度
  • 视频网站费用wordpress 数据库 开发
  • 360网站外链建设六安市城乡建设网站
  • 好的网站设计特点二维码网站建设源码
  • 北京的制作网站的公司一站式商家服务平台
  • 网站推广方案策划书2000mvc5网站开发之六
  • 大连做网站qq群门户网站建设进度
  • 国家建设部网站注册工程师人员查询网站建设开发实训总结