TcpTrace路由解析,参考页面-http://www.cnblogs.com/artech/archive/2008/09/19/1294227.html

TcpTrace工具下载地址:http://www.piaodown.com/soft/43538.htm

原理:模拟路由的方式进行客户端的消息转发,回复。如图:

代码结构如下:

分别为ICalculator:

using System.Linq;
using System.Text;
using System.ServiceModel; namespace Artech.TcpTraceDemo.Contracts
{
[ServiceContract(Namespace = "http://www.artech.com/")]
public interface ICalculator
{
[OperationContract]
double Add(double x, double y);
}
}

Service:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Artech.TcpTraceDemo.Contracts; namespace Artech.TcpTraceDemo.Services
{
public class CalculatorService:ICalculator
{ public double Add(double x, double y)
{
return x + y;
}
}
}

Hosting

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using Artech.TcpTraceDemo.Services; namespace Artech.TcpTraceDemo.Hosting
{
class Program
{
static void Main(string[] args)
{
using (ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService)))
{
serviceHost.Open();
Console.Read();
}
}
}
}

Hosting,Appconfig

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel> <bindings>
<customBinding>
<binding name="SimpleBinding">
<textMessageEncoding />
<httpTransport />
</binding>
</customBinding>
</bindings>
<services>
<service name="Artech.TcpTraceDemo.Services.CalculatorService">
<endpoint address="http://127.0.0.1:9999/CalculatorService" binding="customBinding"
bindingConfiguration="SimpleBinding" contract="Artech.TcpTraceDemo.Contracts.ICalculator" listenUri="http://127.0.0.1:8888/CalculatorService"></endpoint>
</service> </services> </system.serviceModel>
</configuration>

Clients:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Artech.TcpTraceDemo.Contracts;
using System.ServiceModel; namespace Artech.TcpTraceDemo.Clients
{
class Program
{
static void Main(string[] args)
{
using (ChannelFactory<ICalculator> ChannelFactory = new ChannelFactory<ICalculator>("CalculatorService"))
{
ICalculator calculator = ChannelFactory.CreateChannel();
using (calculator as IDisposable)
{
Console.WriteLine("x+y={2} where x={0} and y={1}", , , calculator.Add(,)); }
} Console.ReadLine();
}
}
}

Clients,Appconfig

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<customBinding>
<binding name="SimpleBinding">
<textMessageEncoding />
<httpTransport />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="http://127.0.0.1:9999/CalculatorService" binding="customBinding"
bindingConfiguration="SimpleBinding" contract="Artech.TcpTraceDemo.Contracts.ICalculator"
name="CalculatorService"></endpoint>
</client>
</system.serviceModel>
</configuration>

WCF技术解剖2-TcpTracer路由解析代码的更多相关文章

  1. 【朝夕技术专刊】RabbitMQ路由解析(上篇)

    欢迎大家阅读<朝夕Net社区技术专刊> 我们致力于.NetCore的推广和落地,为更好的帮助大家学习,方便分享干货,特创此刊!很高兴你能成为忠实读者,文末福利不要错过哦! 上篇文章介绍了如 ...

  2. bottle.py中的路由解析代码

    # Routing def compile_route(route): """ Compiles a route string and returns a precomp ...

  3. ASP.NET Web API路由解析

    前言 本篇文章比较长,仔细思考阅读下来大约需要15分钟,涉及类图有可能在手机显示不完整,可以切换电脑版阅读. 做.Net有好几年时间了从ASP.NET WebForm到ASP.NET MVC再到ASP ...

  4. WCF技术剖析之三十:一个很有用的WCF调用编程技巧[下篇]

    原文:WCF技术剖析之三十:一个很有用的WCF调用编程技巧[下篇] 在<上篇>中,我通过使用Delegate的方式解决了服务调用过程中的异常处理以及对服务代理的关闭.对于<WCF技术 ...

  5. WCF技术剖析之二十二: 深入剖析WCF底层异常处理框架实现原理[中篇]

    原文:WCF技术剖析之二十二: 深入剖析WCF底层异常处理框架实现原理[中篇] 在[上篇]中,我们分别站在消息交换和编程的角度介绍了SOAP Fault和FaultException异常.在服务执行过 ...

  6. WCF技术剖析之四:基于IIS的WCF服务寄宿(Hosting)实现揭秘

    原文:WCF技术剖析之四:基于IIS的WCF服务寄宿(Hosting)实现揭秘 通过<再谈IIS与ASP.NET管道>的介绍,相信读者已经对IIS和ASP.NET的请求处理管道有了一个大致 ...

  7. WCF技术剖析之一:通过一个ASP.NET程序模拟WCF基础架构

    原文:WCF技术剖析之一:通过一个ASP.NET程序模拟WCF基础架构 细算起来,已经有好几个月没有真正的写过文章了.近半年以来,一直忙于我的第一本WCF专著<WCF技术剖析>的写作,一直 ...

  8. 《WCF技术剖析》博文系列汇总[持续更新中]

    原文:<WCF技术剖析>博文系列汇总[持续更新中] 近半年以来,一直忙于我的第一本WCF专著<WCF技术剖析(卷1)>的写作,一直无暇管理自己的Blog.在<WCF技术剖 ...

  9. 利用WCF技术降低系统之间的耦合度

    为了降低本系统各个组件之间的耦合度,本系统将BLL层采用WCF技术发布为Web Service,以供UI层调用. 前面我们已经介绍过,为什么UI层不直接调用BLL层,而是要经过UI->Servi ...

随机推荐

  1. yii2邮箱发送

    yii2 邮件发送  163邮箱 1.在配置文件main-local.php components=>[]里面配置 'mailer' => [ 'class' => 'yii\swi ...

  2. ubuntu安装tomcat7

    1. 下载apache-tomcat-7.0.64.tar.gz 进入tomcat官网:http://tomcat.apache.org/download-70.cgi下载相应的压缩包: 2. 上传安 ...

  3. 裸机——wdt

    1. 首先晓得看门狗的基本知识 看门狗是带复位功能的定时器,用于在系统跑飞时复位系统. 接下来按照上次的知识对看门狗进行推导 看门狗的关键词是 定时器 复位 定时器 关键是 时间段 中断 时间段 关键 ...

  4. python基础之继承派生、组合、接口和抽象类

    类的继承与派生 经典类和新式类 在python3中,所有类默认继承object,但凡是继承了object类的子类,以及该子类的子类,都称为新式类(在python3中所有的类都是新式类) 没有继承obj ...

  5. stm32--free modbus 1.5.0移植(作为从机)

    添加文件 获取原始free modbus library(官网) 将...\freemodbus-v1.5.0\demo\BARE中的所有文件复制到...\freemodbus-v1.5.0\modb ...

  6. Lambda与LINQ

    Lambda与LINQ写法对比: 上为Lambda 下为LINQ 显示指定列 Students.select(u=>(new {Name=u.Sname,Address=u.Saddress}) ...

  7. 修改window 10 开始菜单问题

    cmd->powershell Get-AppxPackage | % { Add-AppxPackage -DisableDevelopmentMode -Register "$($ ...

  8. 使用python 3导入MySQLdb 报No module named 'MySQLdb'异常错误

    MySQLdb只支持Python2.*,还不支持3.* 可以用PyMySQL代替安装PyMySQL后,在使用模块时使用import pymysql as MySQLdb 后续使用方式与MySQLdb  ...

  9. 1004 Counting Leaves (30 分)(树的遍历)

    给出一棵树,问每一层各有多少叶子节点 dfs遍历树 #include<bits/stdc++.h> using namespace std; vector<]; int n,m; i ...

  10. mysql Access denied for user 'root'@'localhost'问题解决

    问题描述: 系统安装mysql的过程中,没有提示配置用户名和密码相关的信息,安装完毕后,登录报错. 表现现象为: mysql -u root -p [输入root密码] 界面提示: ERROR 169 ...