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 ...
随机推荐
- PHP常用的自定义函数
PHP常用的自定义函数 目录 php常用自定义函数类下载 php 设置字符编码为utf-8 路径格式化(替换双斜线为单斜线) 转码 打印输出 api返回信息 字符串截取 方法一: 方法二: 数组 字符 ...
- php 变量的8类类型
整形,布尔,浮点形,字符串,数组,资源,对象和null php数据类型之查看和判断数据类型 php数据类型之自动转换和强制转换
- 提高mysql性能(like搜索替换 )
一 .mysql用find_in_set代替like搜索提高性能 SELECT * from mobantestinfo1 where find_in_set('33',info2); 二 .使用内部 ...
- python 初学函数
#len # s = '金老板小护士' # len(s) # def my_len(): #自定义函数 # i = 0 # for k in s: # i += 1 # print(i) # # le ...
- awk命令例子详解
awk -F: '{print "Number of dields: "NF}' passwd 字段分隔符设为冒号,所以每条记录的字段数变成7: awk '{print &quo ...
- Aizu:0009- Prime Number
Prime Number Time limit 1000 ms Memory limit 131072 kB Problem Description Write a program which rea ...
- EF实体部分更新的问题
之前遇到只更新部分的问题:如前端修改用户信息(不修改密码),传实体到后台,这个实体是没有密码,这样一来要更新的话,得先去数据库通过传过来的实体的ID读取这条记录,然后将改动的部分填到查出来的记录中,再 ...
- HDFS HA 的 hdfs-site.xml
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?> <!-- Licens ...
- poj2001Shortest Prefixes(trie)
Shortest Prefixes Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 18687 Accepted: 808 ...
- MyEclipse - 问题集 - build properties does not exist
方案1 受MyEclipse生成的项目文件.project影响,检查其中是否含有“<nature>org.eclipse.pde.PluginNature</nature>”, ...