WCF技术解剖2-TcpTracer路由解析代码
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路由解析代码的更多相关文章
- 【朝夕技术专刊】RabbitMQ路由解析(上篇)
欢迎大家阅读<朝夕Net社区技术专刊> 我们致力于.NetCore的推广和落地,为更好的帮助大家学习,方便分享干货,特创此刊!很高兴你能成为忠实读者,文末福利不要错过哦! 上篇文章介绍了如 ...
- bottle.py中的路由解析代码
# Routing def compile_route(route): """ Compiles a route string and returns a precomp ...
- ASP.NET Web API路由解析
前言 本篇文章比较长,仔细思考阅读下来大约需要15分钟,涉及类图有可能在手机显示不完整,可以切换电脑版阅读. 做.Net有好几年时间了从ASP.NET WebForm到ASP.NET MVC再到ASP ...
- WCF技术剖析之三十:一个很有用的WCF调用编程技巧[下篇]
原文:WCF技术剖析之三十:一个很有用的WCF调用编程技巧[下篇] 在<上篇>中,我通过使用Delegate的方式解决了服务调用过程中的异常处理以及对服务代理的关闭.对于<WCF技术 ...
- WCF技术剖析之二十二: 深入剖析WCF底层异常处理框架实现原理[中篇]
原文:WCF技术剖析之二十二: 深入剖析WCF底层异常处理框架实现原理[中篇] 在[上篇]中,我们分别站在消息交换和编程的角度介绍了SOAP Fault和FaultException异常.在服务执行过 ...
- WCF技术剖析之四:基于IIS的WCF服务寄宿(Hosting)实现揭秘
原文:WCF技术剖析之四:基于IIS的WCF服务寄宿(Hosting)实现揭秘 通过<再谈IIS与ASP.NET管道>的介绍,相信读者已经对IIS和ASP.NET的请求处理管道有了一个大致 ...
- WCF技术剖析之一:通过一个ASP.NET程序模拟WCF基础架构
原文:WCF技术剖析之一:通过一个ASP.NET程序模拟WCF基础架构 细算起来,已经有好几个月没有真正的写过文章了.近半年以来,一直忙于我的第一本WCF专著<WCF技术剖析>的写作,一直 ...
- 《WCF技术剖析》博文系列汇总[持续更新中]
原文:<WCF技术剖析>博文系列汇总[持续更新中] 近半年以来,一直忙于我的第一本WCF专著<WCF技术剖析(卷1)>的写作,一直无暇管理自己的Blog.在<WCF技术剖 ...
- 利用WCF技术降低系统之间的耦合度
为了降低本系统各个组件之间的耦合度,本系统将BLL层采用WCF技术发布为Web Service,以供UI层调用. 前面我们已经介绍过,为什么UI层不直接调用BLL层,而是要经过UI->Servi ...
随机推荐
- C++基础 inline 默认参数 函数占位参数 函数重载
1. inline内联函数 内联函数用于替换宏, 实例: 其中宏和 ++ 连用有副作用. #include "iostream" using namespace std; #def ...
- 关于Java对象作为参数传递是传值还是传引用的问题
前言 在Java中,当对象作为参数传递时,究竟传递的是对象的值,还是对象的引用,这是一个饱受争议的话题.若传的是值,那么函数接收的只是实参的一个副本,函数对形参的操作并不会对实参产生影响:若传的是引用 ...
- filter() 函数的使用
Python3 filter() 函数 描述 filter() 函数用于过滤序列,过滤掉不符合条件的元素,返回一个迭代器对象,如果要转换为列表,可以使用 list() 来转换. 该接收两个参数,第一个 ...
- TouTiao开源项目 分析笔记6
1.NewsChannelBean简单类笔记 1.1.Comparable接口的实现和使用 参考文章:Comparable接口的实现和使用. 因为NewsChannelBean实现了Comparabl ...
- 20145202马超 《Java程序设计》第三周学习总结
************************http://git.oschina.net/tuolemi/java这是git的那个网址********************* 函数的重载:在同一 ...
- 5-1 练习css 总结
1. 边框 border:3px dotted; border: 2px solid yellow; 背景颜色 background-color: red; 外攘 margin:20px 0 20px ...
- luoguP1726 上白泽慧音
P1726 上白泽慧音 题目描述 在幻想乡,上白泽慧音是以知识渊博闻名的老师.春雪异变导致人间之里的很多道路都被大雪堵塞,使有的学生不能顺利地到达慧音所在的村庄.因此慧音决定换一个能够聚集最多人数的村 ...
- how to export chrome speed dial extension?
locate chrome-extension_dgpdioedihjhncjafcpgbbjdpbbkikmi_0.localstorage, copy it to you want, everyt ...
- 编译gearman提示缺少boost
编译german时提示缺少boost: checking for boostlib >= 1.39... configure: We could not detect the boost lib ...
- ironic state information
参考: http://blog.csdn.net/zhonglinzhang/article/details/74202562 http://blog.csdn.net/wanghuiict/arti ...