- 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).
- PS是這樣玩的:輕松掌握 Photoshop 通關秘籍
- Getting Started with Microsoft Application Virtualization 4.6
- Microsoft Visual C++ Windows Applications by Example
- 使用AADL的模型基工程:SAE體系結構分析和設計語言入門
- SolidWorks 2008機械設計一冊通
- ASP.NET MVC 2 Cookbook
- 數碼攝影后期處理秘笈:Photoshop CC專業調色(第2版)
- Power Query從入門到精通
- 中文版After Effects 2022基礎教程
- Photoshop數字圖像處理
- MATLAB在日常計算中的應用
- Photoshop+Illustrator+CorelDRAW一站式高效學習一本通
- Photoshop 2020實戰從入門到精通(超值版)
- Building SOA/Based Composite Applications Using NetBeans IDE 6
- Photoshop CS5數字圖像處理