启动WCF多个服务方法
引用就不说明,直接贴上:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.Configuration;
using System.Collections;
public class WCFServiceHelper
{
private static List<ServiceHost> _ServiceHost = new List<ServiceHost>();
/// <summary>
/// 启动WCF服务
/// </summary>
public static void ServiceStart()
{
//配置的服务地址,自己配置
string WCFServiceAddress = ConfigurationManager.AppSettings["WCFServiceAddress"];
/* 配置的格式如
<appSettings>
<add key="WCFServiceAddress" value="net.tcp://127.0.0.1:8888"/>
</appSettings>
*/
//获取配置文件的服务名称,就是那些接口,形式看具体需求去配
/* 如果多个服务要逗号分隔开,My.IService1,My.IService2服务接口,My.Service.Service1,My.Service.Service2服务实现
<WCFServices>
<add key="My.IService1,My.IService2" value="My.Service.Service1,My.Service.Service2"/>
多个就继续往下配置
</WCFServices>
*/
IDictionary WCFDict = ConfigurationManager.GetSection("WCFServices") as IDictionary;//获取自定义的节点
if (WCFDict != null)
{
string ServiceName = string.Empty;
NetTcpBinding Binding;
string[] Services;
string[] IServices;
ServiceHost host;
foreach (DictionaryEntry dict in WCFDict)//这里面遍历绑定服务
{
ServiceName = dict.Value.ToString();
Services = ServiceName.Split(',')[0].Split('.');
IServices = dict.Key.ToString().Split(',')[0].Split('.');
Binding = new NetTcpBinding("TcpSet");//绑定协议
Binding.ReceiveTimeout = new TimeSpan(0, 30, 0);
Binding.Security.Mode = SecurityMode.None;
host = new ServiceHost(Type.GetType(ServiceName));
host.AddServiceEndpoint(Type.GetType(dict.Key.ToString()), Binding, string.Format("{0}/{1}", WCFServiceAddress, Services[Services.Length - 1]));
try
{
host.Open();
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine(string.Format("{0}启动成功", string.Format("{0}/{1}", WCFServiceAddress, Services[Services.Length - 1])));
_ServiceHost.Add(host);
}
catch (Exception exception)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(string.Format("{0}启动失败,失败原因:{1}", string.Format("{0}/{1}", WCFServiceAddress, Services[Services.Length - 1]),exception.ToString()));
}
}
}
}
/// <summary>
/// 停止WCF服务
/// </summary>
public static void ServiceStop()
{
foreach (ServiceHost host in _ServiceHost)
{
host.Close();
}
}
}
/*绑定的配置
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="TcpSet" maxBufferSize="2147483647" receiveTimeout="00:30:00" sendTimeout="00:30:00" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" maxConnections="100000">
<readerQuotas maxDepth="32" maxStringContentLength="2147483647 " maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
</binding>
</netTcpBinding>
</bindings>
</system.serviceModel>
*/
启动WCF多个服务方法的更多相关文章
- IOS调用WCF提供的服务方法,但是方法的参数是WCF那边自定义的对象,这样有办法调用么,如果可以IOS应该怎么传参呢?请问有了解的么,
最近做一个项目后端使用WCF接收Android手机拍照并带其它参数保存到服务器里:刚好把最近学习的WCF利用上,本以为是个比较简单的功能应该很好实现,没想到其中碰到不少问题,在网上搜索很久一直没有想到 ...
- Appium+Python app自动化测试之脚本启动和停止Appium服务
研究了一段时间的Appium android app的自动化测试,工作中需要连接多台手机终端同时执行测试用例,我实现的方式是获取用例中需要执行用例的设备id个数以及实际连接到的设备数(通过adb de ...
- 利用反射,批量启动WCF服务
对于WCF的宿主启动来说,有好多方法,单独启动也很简单,可以根据业务需要来自由选择(单独启动方法这里就不做解释) 对于业务服务比较多的时候,往往需要多个服务来承载系统,但是如果将服务启动单独写代码启动 ...
- centos 6 与 centos 7 服务开机启动、关闭设置的方法
简单说明下 centos 6 与 centos 7 服务开机启动.关闭设置的方法: centos 6 :使用chkconfig命令即可. 我们以apache服务为例: #chkconfig --add ...
- 关于在安装MySQL时报错"本地计算机上的mysql服务启动后停止,某些服务在未由其他服务或程序使用时将自动停止"的解决方法
首先将你下载的MySQL安装或者解压(对应安装版和解压版),下载地址http://dev.mysql.com/downloads/mysql/ 然后复制你安装目录中的my-default.ini,更改 ...
- Windows无法启动 VMware Workstation server服务解决方法
Windows无法启动VMware Workstation server服务, 可以通过删除datastores.xml文件来解决. 具体操作步骤如下: 1.在系统盘目录下,找到C:\ProgramD ...
- [WCF编程]8.服务实例的生命周期
一.服务实例的生命周期概览 我们已经直到,通过显式调用Close方法或等待默认的超时时间到来,都可以释放服务实例.但是,在会话连接里,经常需要按一定顺序调用方法. 二.分步操作 会话契约的操作有时隐含 ...
- WCF初探-10:WCF客户端调用服务
创建WCF 服务客户端应用程序需要执行下列步骤: 获取服务终结点的服务协定.绑定以及地址信息 使用该信息创建 WCF 客户端 调用操作 关闭该 WCF 客户端对象 WCF客户端调用服务存在以下特点: ...
- 跟我一起学WCF(11)——WCF中队列服务详解
一.引言 在前面的WCF服务中,它都要求服务与客户端两端都必须启动并且运行,从而实现彼此间的交互.然而,还有相当多的情况希望一个面向服务的应用中拥有离线交互的能力.WCF通过服务队列的方法来支持客户端 ...
随机推荐
- JavaScript笔记:函数
函数是定义一次但却可以调用或执行任意多次的代码块. 一.函数定义 javascript中的函数使用function关键字来定义,常用的函数定义分为三种形式: 声明式函数定义 function sum( ...
- Action向前台输出
import java.io.IOException;import java.io.PrintWriter; import javax.servlet.http.HttpServletResponse ...
- ruby on rails 在centos 7下的安装配置
因为想安装最新版本,所以通过编译安装. 安装前准备工具和库文件: sudo yum install gcc gcc-c++ openssl-devel readline-devel gdbm-deve ...
- asp.net上传文件超过了最大请求长度[转]
错误消息:超过了最大请求长度 错误原因:asp.net默认最大上传文件大小为4M,运行超时时间为90S. 解决方案 1. 修改web.config文件可以改变这个默认值 ...
- MySQL学习(一)
mysql left join,right join,inner join用法分析 left join:是以A表的记录为基础的,A可以看成左表,B可以看成右表,left join是以左表为准的. 换句 ...
- --- shell 扩展的顺序
1. 扩展(expansion)是bash 解释器的重要的概念: 2. 命令替换是扩展里面的一种 3. 基本结构是: “字符串准备(花括号,波浪线,参数和变量扩展,命令替换),单词分割,路径扩展” h ...
- mobx源码解读2
我们将上节用到的几个类的构造器列举一下吧: function Reaction(name, onInvalidate) { if (name === void 0) { name = "Re ...
- {MBR}{Grub}win7+Linux恢复MBR
准备:win7安装盘,Linux安装盘 Step1:在linux下查看一下硬盘的信息fdisk -l,找到hd0和ext分区的信息 Step2: 重启插入win7安装盘,对windows系统恢复Gru ...
- ArcEngine中打开各种数据源(WorkSpace)的连接
(SDE.personal/File.ShapeFile.CAD数据.影像图.影像数据集) ArcEngine 可以接受多种数据源.在开发过程中我们使用了如下几种数据源 1.企业数据库(SDE) 企业 ...
- ArcGIS Engine 刷新问题
link: http://www.cnblogs.com/Jingkunliu/archive/2013/01/10/2854710.html PartialRefresh方法是部分刷新,效率方面比单 ...