- Microsoft Windows Communication Foundation 4.0 Cookbook for Developing SOA Applications
- Steven Cheng
- 463字
- 2021-04-13 17:04:05
WCF supports exposing a single service through multiple heterogeneous endpoints. Another great feature is letting multiple endpoints listen over the same physical transport address. For example, you want to host a WCF service that has multiple endpoints exposed. However, you only have a single HTTP URL open for listening. Then you can use this feature to make all those endpoints (as long as they’re using the same transport protocol) listen on the same URL.
Our sample service will expose two endpoints (one is IFoo and the other is IBar) and both of them will listen on the same HTTP URL:
- The first thing we need to do is configure the service endpoints. We will still specify different values for the
address
attribute of the two endpoints. However, we will use a special attribute namedlistenUri
to supply the physical address (identical for both endpoints). The following screenshot shows the usage of both attributes: - It is also important to configure the client endpoint so that the client proxy or
ChannelFactory
can correctly locate the service endpoint. WCF provides aClientViaBehavior
type for specifying the physical address of a client endpoint. You can use theChannelFactory.Endpoint.Behaviors
collection to inject the behavior in code, shown as follows:ChannelFactory<SharedAddressService.IFoo> fooFactory = new ChannelFactory<SharedAddressService.IFoo>(new WSHttpBinding(SecurityMode.None)); SharedAddressService.IFoo foo = fooFactory.CreateChannel( new EndpointAddress(“urn:Foo”), /* logical address */ new Uri(“http://localhost:8731/FooBarService/Operations”)); /*physical address*/ foo.Foo();
Alternatively, you can also use the
<clientVia>
element to supply the physical address in a configuration file, as shown in the following screenshot:
Generally, we will use the address
attribute to specify the URL on which the endpoint will listen. However, this address
is actually a logical address and WCF runtime will use it as a physical address also, if we haven’t explicitly provided a physical address. The listenUri
, on the contrary, represents the physical transport address the service endpoint listens on.
Also, for the endpoints that share the same physical address, they will share the same service dispatcher and channel stack. Then, how does the WCF runtime differentiate these operation requests when there are multiple endpoints listening on a single physical address? The answer is WCF runtime will try to resolve the request target by the combination of two parts:
- The Service/Operation Contract
- The logical address specified the via
address
attribute
Therefore, the dispatcher/channel stack can correctly redirect the requests to the corresponding endpoint even if we supply an identical value for both logical and physical address.
For more in-depth explanation on WCF Addressing, you can have a look at the WCF Addressing In Depth MSDN article written by Aaron Skonnard (http://msdn.microsoft.com/en-us/magazine/cc163412.aspx).
- Moodle 2.0 E/Learning Course Development
- HTML5 Multimedia Development Cookbook
- CAXA CAD電子圖板2020工程制圖
- ERP沙盤模擬簡明教程
- 無師自通AutoCAD:中文版室內設計
- 零基礎學數碼攝影后期
- 剪映視頻后期剪輯零基礎入門到精通
- Photoshop網店美工實例教程(第2版 全彩微課版)
- VRP11/3ds Max虛擬現實制作標準實訓教程
- 音樂制作7天速成:Cubase編曲教程
- NHibernate 3 Beginner's Guide
- 技藝非凡Photoshop+SAI繪畫創作技法揭秘
- 藝術二維碼設計與制作完全攻略 PHOTOSHOP+ILLUSTRATOR+FLASH
- 電磁場數值計算及基于FreeFEM的編程實現
- 剪映專業版:PC端短視頻制作(全彩慕課版)