启动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通过服务队列的方法来支持客户端 ...
随机推荐
- 修复HTTP 503错误
要解决此问题,按照下列步骤操作: 1.验证是否已为虚拟服务器配置了应用程序池.默认的应用程序池是MSSharePointPortalAppPool. 请按照下列步骤来确定虚拟服务器正在使用的应用程序池 ...
- 安卓手机屏幕录像之scr
打开SCR Screen Recorder,屏幕会显示录像控制面板,点击“开始”按钮就可以开始录像: - 停止录像的方法有两种.一种是锁屏,锁屏后等待2秒,录像文件会自动保存到SD卡,另外一种是重新打 ...
- javascript Windouw 转自 http://www.cnblogs.com/kissdodog/archive/2013/01/01/2841464.html
javascript之window对象 window :window对象是BOM中所有对象的核心,除了是BOM中所有对象的父对象外,还包含一些窗口控制函数. 1.全局的window对象 JavaScr ...
- PAT 乙级 1005. 继续(3n+1)猜想 (25)
1005. 继续(3n+1)猜想 (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 卡拉兹(Callatz)猜想已经在1001中给出了描述.在这个题目里,情 ...
- 使用JDBC访问SQLServer 2008
使用JDBC访问SQLServer 2008 // 准备数据库驱动程序 String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriv ...
- DBTest/1.TestWrite fails: MDB_BAD_TXN: Transaction cannot recover - it must be aborted
今天,终于把这个困扰我好久的问题解决了.心累之余,分享给大家. 主要问题是编译caffe的时候报错了: [----------] 5 tests from DBTest/1, where TypePa ...
- Android 之Html的解析(使用jsoup)
Runnable run=new Runnable() { @Override public void run() { // TODO Auto-generated method stub useri ...
- 使用Gson解析json
前边的博客说过将json解析成java的方法,使用的是 这几个jar包,但是在解析时层遇到一个问题,就是在将时间字符串转换为java的Timestamp对象时会抛出异常,这个问题一直放在哪里没有去解决 ...
- leetcode 4. Median of Two Sorted Arrays
https://leetcode.com/problems/median-of-two-sorted-arrays/ There are two sorted arrays nums1 and num ...
- c# XML和实体类之间相互转换(序列化和反序列化)[砖]
link: http://blog.okbase.net/haobao/archive/62.html by: 好饱 我们需要在XML与实体类,DataTable,List之间进行转换,下面是XmlU ...