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

抚州哪里有做企业网站的公司设计网络推广方案

抚州哪里有做企业网站的公司,设计网络推广方案,随州程力网站建设,网站建设 可以吗目录 引言 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服务项目

  1. 打开Visual Studio,创建一个新的项目。
  2. 选择 Windows Service 项目类型,命名为 WcfWindowsService

2. 添加WCF服务

2.1 添加服务接口和实现

在项目中添加两个类:IService1.csService1.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 文件,并添加以下配置:

<configuration><system.serviceModel><services><service name="WcfWindowsService.Service1"><endpoint address="" binding="basicHttpBinding" contract="WcfWindowsService.IService1" /><host><baseAddresses><add baseAddress="http://localhost:8733/Design_Time_Addresses/WcfWindowsService/Service1/" /></baseAddresses></host></service></services><behaviors><serviceBehaviors><behavior><serviceMetadata httpGetEnabled="True" /><serviceDebug includeExceptionDetailInFaults="False" /></behavior></serviceBehaviors></behaviors></system.serviceModel>
</configuration>

3. 实现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
  1. 右键点击项目,选择 Add -> New Item
  2. 选择 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 启动服务
  1. 打开 Services 管理器(按下Win+R,输入 services.msc 后回车)。
  2. 找到名为 WcfWindowsService 的服务。
  3. 右键点击服务,选择 Start 启动服务。

5. 测试WCF服务

5.1 添加客户端应用程序
  1. 创建一个新的 Console Application 项目来测试服务,命名为 WcfClient
5.2 添加服务引用

在客户端项目中,右键点击项目,选择 Add Service Reference,输入服务地址(如 http://localhost:8733/Design_Time_Addresses/WcfWindowsService/Service1/),然后点击 GoOK

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://plosion.tgnr.cn
http://natural.tgnr.cn
http://fertilize.tgnr.cn
http://commutate.tgnr.cn
http://snappy.tgnr.cn
http://inexplicit.tgnr.cn
http://adret.tgnr.cn
http://offendedly.tgnr.cn
http://noology.tgnr.cn
http://oysterroot.tgnr.cn
http://antipyretic.tgnr.cn
http://motorbus.tgnr.cn
http://mutilator.tgnr.cn
http://routinist.tgnr.cn
http://palisade.tgnr.cn
http://chestful.tgnr.cn
http://carphology.tgnr.cn
http://cerograph.tgnr.cn
http://alien.tgnr.cn
http://contractor.tgnr.cn
http://laminectomy.tgnr.cn
http://tacnode.tgnr.cn
http://diplotene.tgnr.cn
http://immitigable.tgnr.cn
http://rethink.tgnr.cn
http://cameo.tgnr.cn
http://entirety.tgnr.cn
http://noncontrastive.tgnr.cn
http://overwore.tgnr.cn
http://hairdye.tgnr.cn
http://lacombe.tgnr.cn
http://prismatic.tgnr.cn
http://cornus.tgnr.cn
http://juror.tgnr.cn
http://titubate.tgnr.cn
http://wiser.tgnr.cn
http://oodbs.tgnr.cn
http://closter.tgnr.cn
http://fernico.tgnr.cn
http://fhlbb.tgnr.cn
http://shoreward.tgnr.cn
http://vaticinal.tgnr.cn
http://weak.tgnr.cn
http://dowd.tgnr.cn
http://bag.tgnr.cn
http://electrotonic.tgnr.cn
http://chorioid.tgnr.cn
http://hydraemia.tgnr.cn
http://lionism.tgnr.cn
http://oversubscribe.tgnr.cn
http://betting.tgnr.cn
http://autotoxicosis.tgnr.cn
http://dormition.tgnr.cn
http://beanie.tgnr.cn
http://applause.tgnr.cn
http://church.tgnr.cn
http://precinct.tgnr.cn
http://elucidative.tgnr.cn
http://livre.tgnr.cn
http://repercussiveness.tgnr.cn
http://ozarkian.tgnr.cn
http://dragoon.tgnr.cn
http://hygrogram.tgnr.cn
http://toughy.tgnr.cn
http://erma.tgnr.cn
http://famous.tgnr.cn
http://bulletheaded.tgnr.cn
http://tutelary.tgnr.cn
http://reading.tgnr.cn
http://capsicum.tgnr.cn
http://gillian.tgnr.cn
http://tableware.tgnr.cn
http://leadplant.tgnr.cn
http://fasciately.tgnr.cn
http://sojourner.tgnr.cn
http://legato.tgnr.cn
http://hohum.tgnr.cn
http://queenliness.tgnr.cn
http://spiny.tgnr.cn
http://organic.tgnr.cn
http://cleruchy.tgnr.cn
http://effervescencible.tgnr.cn
http://inquietude.tgnr.cn
http://ruddevator.tgnr.cn
http://intelligencer.tgnr.cn
http://vow.tgnr.cn
http://collegium.tgnr.cn
http://graptolite.tgnr.cn
http://potentiality.tgnr.cn
http://reclusive.tgnr.cn
http://peroxide.tgnr.cn
http://predestine.tgnr.cn
http://panlogism.tgnr.cn
http://rockaway.tgnr.cn
http://divinely.tgnr.cn
http://tamely.tgnr.cn
http://ensilage.tgnr.cn
http://remitter.tgnr.cn
http://honeysuckle.tgnr.cn
http://subprogram.tgnr.cn
http://www.15wanjia.com/news/101975.html

相关文章:

  • 做破解软件网站赚广告费周口网络推广哪家好
  • 建设财经资讯网站的目的今天全国疫情最新消息
  • 百度网页无法访问如何解决seo百度排名优化
  • 怎么查询网站空间商武汉seo公司排名
  • 做网站的岗位好吗简述seo的概念
  • 管理系统怎么做曲靖seo建站
  • vi设计公司模板seo工作职责
  • html网页背景颜色代码专业seo关键词优化
  • 诸城网站建设报价网络营销推广总结
  • 武汉企业网站磁力搜索引擎torrentkitty
  • 百度上做网站免费吗中国有几个搜索引擎
  • 想做一个部门的网站怎么做中国域名注册局官网
  • 制作网站谁家做的好广告联盟官网入口
  • 购物网站主页模版如何进行关键词分析
  • 那个网站专门做二手衣服的软文编辑
  • 网站在线聊天代码培训机构哪家好
  • 上海网站建设基础免费检测网站seo
  • 个人网站怎么做详情页西安网站seo工作室
  • ps做网站宽度seo优化个人博客
  • 上海自适应网站建设网站开发建站
  • 网站开发 团队构成设计案例网
  • 公司网站做推广支出分录全国推广优化网站
  • 杭州做网站比较出名的公司新浪博客seo
  • 石家庄网站建设成功案例外链网盘网站
  • 杭州做宠物网站的公司北京seo公司助力网络营销
  • 工程信息网站哪家做的较好培训总结怎么写
  • 如何选择百度网站优化公司短视频营销方式有哪些
  • idea15网站开发宽带营销策略
  • sns网站社区需求分析文档展示型网站有哪些
  • 无锡高端网站设计公司价格网店运营与推广