现在WCF 4.0内置了路由服务——System.ServiceModel.Routing.RoutingService,可以在 System.ServiceModel.Routing.dll 中找到。
比如下面的场景会使用到路由服务:只暴露一个外部公开的 Endpoint 映射到内部的多个的服务上。
路由服务使用的消息筛选器提供常用消息选择功能,例如,终结点的名称、SOAP 操作或消息已发送到的地址或地址前缀。也可以使用 AND 条件连接筛选器,这样,仅当消息同时与两个筛选器匹配时,才会将消息路由至某个终结点。此外,还可以通过创建自己的 MessageFilter 实现来创建自定义筛选器。(MSDN:消息筛选器)
OK,废话少说下面做一个实例来看看 RoutingService 该如何配置。
1. Console Hosting Request/Reply WCF Service Routing (示例代码下载)
(1) 创建一个普通的Wcf Service Library (使用Console Hosting)
Console Host
app.config
为了测试,Service1 使用的是 PerSession,当 Service1 被第一次调用时,服务端构造一次 Service1 实例。并在之后的调用中保持该 Session。
SetName 将保存一个值,GetName 则取出该值。
(2) 创建 Wcf Routing Service Host(使用Console Hosting)
首先添加System.ServiceModel.Routing.dll, using System.ServiceModel.Routing;
重点在于 RoutingService 的配置文件,详细参看代码中的注释说明。
(3) 创建客户端应用
首先是客户端代理的生成,通过 Wcf Routing Service 好像没有办法能访问到真实服务的wsdl,
因此我的做法是先利用真实服务的wsdl生成代理,然后修改客户端配置文件。
比如这个例子中真实服务地址是:http://localhost:20000/WcfRoutingServiceTest/Service1
Wcf Routing Service的地址是: http://localhost:20002/WcfRoutingServiceTest/router/service1
修改后的客户端配置如下:
客户端调用:
(4) 运行
运行结果显示,client -> Routing Service -> Wcf Service1 注意当PerSession时,如果在RoutingService 每个filter 对于 WcfService1 都是独立的Session。
http://topic.csdn.net/u/20111005/15/69a4c0b8-63ab-4528-a520-6a8568ee17d3.html
----------------------------- 分割线 ----------------------------
2. IIS Hosting Request/Reply WCF Service Routing(示例代码下载)
当使用IIS Hosting时,我们创建的 WCF 工程模板就需要改为 Wcf Service Application了。下面介绍如何配置 Wcf Service Application 中的 Routing Service
这次需要实现的是在一个 Routing Service 中路由多个不同地址的 Wcf Service (如文章开头的图片所示)
(1) Solution Overview
其中:
WcfRoutingService :http://localhost:20001/RoutingService.svc
WcfService1 : http://localhost:20002/Service1.svc
WcfService2: http://localhost:20003/Service1.svc
(2) 配置 WcfRoutingService
因为 WcfRoutingService 里没有任何 svc 文件,这里利用了 WCF 4.0 的无 svc 文件激活服务的新特性:
另外,上面已经提到对于 WCF Request/Reply 模型的 filterTable 不允许多播,那么在 Routing Service 里,需要配置响应个数的 Endpoint
完整配置如下:
(3) 创建客户端应用
客户端配置文件
调用
(4) 运行
----------------------------- 分割线 ----------------------------
参考:
http://msdn.microsoft.com/zh-cn/library/ee517419.aspx
http://blogs.profitbase.com/tsenn/?p=23
http://msdn.microsoft.com/zh-cn/library/ee517425.aspx
分享到:
相关推荐
WCF4.0 —— Routing Service 比如下面的场景会使用到路由服务:只暴露一个外部公开的 Endpoint 映射到内部的多个的服务上。 http://blog.csdn.net/fangxinggood/article/details/6872015
wcf4.0英文教材wcf4.0英文教材wcf4.0英文教材
HYPERLINK"http://blog.csdn.net/fangxinggood/article/details/6762632"WCF实例——WindowsServiceHost开发,调试,制作安装包本篇实例介绍如何使用WindowsService来寄宿WCF服务:1.添加WCFServiceLibrary工程,这...
(英文版)WCF 4.0 Multi-tier Services Development with LINQ to Entities Packt Publishing 出版2010, PDF格式
WCF 4.0 Multi-tier Services Development.with LINQ to Entities
Packtpub WCF 4.0 Multi tier Services Development with LINQ to Entities Jun.2010 关于WCF 4.0 和LINQ to Entity 的 新书 流行加时尚的编程利器
wcf 4.0 pdf .net framework 4.0
WCF4.0 内包含 Routing Service 利用路由服务,指向多个wcf服务
[Packt Publishing] WCF 4.0 多层服务开发 —— 使用 LINQ to Entities 技术 (英文版) [Packt Publishing] WCF 4.0 Multi-tier Services Development with LINQ to Entities ======================================...
WCF很好的支持了REST的开发,而RESTful的服务通常是架构层面上的考虑。因为它天生就具有很好的跨平台跨语言的集成能力,几乎所有的语言和网络平台都支持HTTP请求,无需去实现复杂的客户端代理,无需使用复杂的数据...
technology to support these scenarios and gain a clear understanding of how the pieces of WCF 4.0 build upon each other to provide a comprehensive framework to support many aspects of distributed ...
Windows Communication Foundation (WCF)是 Microsoft为构建面向服务的应用提供的分布式通信编程框架,是.NET Framework 3.5的重要组成部分
Selft-host-wcf-rest-service 带有 Angular jsonp 客户端的 selft-host 控制台应用程序 .net 4.0 wcf restservice .net 角余量/*** ^ v ^ { _ }
wcfservice示例wcfservice示例wcfservice示例wcfservice示例wcfservice示例
在REST架构的WCF服务中,它不像一般的WCF服务绑定,有配套的安全模式,实现起来那么简单。RESTWCF服务只能在传输层加密,而一般的WCF服务可以在消息层加密。因此RESTWCF服务启用ASP.NET兼容模式后,它的安全是由ASP...