读书人

WCF基准终结点介绍

发布时间: 2012-10-28 09:54:44 作者: rapoo

WCF标准终结点介绍

一、WCF4.0标准终结点

我们知道,绑定的本质就是一系列相关绑定元素的有序集合,而系统绑定就是基于若干典型的通信场景对相关绑定元素的整合。WCF通过系统绑定对绑定元素进行了定制,那么能否在终结点级别对组成该终结点的ABC(地址、绑定和契约)也进行相应的定制呢?实际上这对于最新版本的WCF是可行的,我们将这个机制称为“标准终结点”。

所谓标准终结点,就是针对典型的通信场景选择组成终结点的要素(主要是绑定和契约)进而创建出一个标准的终结点。在使用的时候,如果你需要的终结点要素和标准终结点完全一致,就无需进行重复的设置;如果不一致,则只需要单独对此进行重新设置以覆盖定义在标准终结点的默认设置。java foreach语句使用总结


比如说,对于用于发布元数据的终结点总是将IMetadataExchange作为其契约,并且在大部分情况下使用MexHttpBinding。如果我们基于这两个元素创建一个标准的MexEndpoint,那么在为服务配置发布元数据的终结点的时候就只需要指定地址就可以了。实际上,WCF确实为我们创建了这么一个标准的MexEndpoint终结点。包含MexEndpoint终结点在内,WCF总共为我们定义了如下面的列表所示的9个标准终结点。

??? mexEndpoint:用于公开服务元数据的标准终结点;
??? dynamicEndpoint:使用 WS-Discovery 在运行时动态查找终结点地址的标准终结点;
??? discoveryEndpoint:由服务用于发送发现消息的标准终结点;
??? udpDiscoveryEndpoint:通过 UDP 多播绑定为发现操作预配的标准终结点;
??? announcementEndpoint:由服务用于发送公告消息的标准终结点;
??? udpAnnouncementEndpoint:由服务用于通过 UDP 绑定发送公告消息的标准终结点;
??? workflowControlEndpoint:可用于对工作流实例调用控制操作的标准终结点;
??? webHttpEndpoint:带有自动添加 WebHttpBehavior行为的WebHttpBinding绑定的标准终结点;
??? webScriptEndpoint:带有自动添加 WebScriptEnablingBehavior行为的WebHttpBinding绑定的标准终结点。

如果你希望直接为某个服务配置一个标准终结点,可以借助于WCF4.0为终结点的配置节添加的一个新的配置属性kind,该属性表示标准终结点名称。在上面的配置中,我为服务配置了一个标准终结点mexEndpoint以实现基于MEX终结点形式的元数据发布。

?? 1: <?xml version="1.0"?>

?? 2: <configuration>

?? 3:?? <system.serviceModel>

?? 4:???? ...

?? 5:???? <services>?????

?? 6:?????? <service name="Artech.WcfServices.Service.CalculatorService" >

?? 7:???????? <host>

?? 8:?????????? <baseAddresses>

?? 9:???????????? <add baseAddress="http://127.0.0.1:3721/calculatorservice"/>

? 10:?????????? </baseAddresses>

? 11:???????? </host>

? 12:???????? <endpoint binding="ws2007HttpBinding" contract="Artech.WcfServices.Contract.ICalculator" />

? 13:???????? <endpoint kind="mexEndpoint" address="mex"/>

? 14:?????? </service>

? 15:???? </services>?

? 16:?? </system.serviceModel>

? 17: </configuration>

对于系统绑定来说,WCF允许你通过配置的方式对其进行定制,标准终结点也不例外。如果标准的终结点默认配置不能满足你的要求,你可以在配置中对其进行相应的定制。在WCF配置节下添加了一个新的子结点<standardEndpoints>,用于对这9个标准终结点进行定制。和自定义绑定一样,你需要为自定义的标准终结点起一个名字。如果某个终结点需要使用到自定义的标准终结点,标准终结点的名称需要设置到终结点配置节的另一个额外的配置属性endpointConfiguration上。android 软体键盘 实现 -- 断点记录

在下面的配置中,我们自定义了一个基于WS-Discovery 1.1的udpDiscoveryEndpoint,并起名为“wsd11”。而这个标准终结点通过终结点配置节的两个属性kind(kind="udpDiscoveryEndpoint")和endpointConfiguration(endpointConfiguration="wsd11")被添加到寄宿的CalculatorService服务的终结点列表中。

?? 1: <?xml version="1.0"?>

?? 2: <configuration>

?? 3:?? <system.serviceModel>

?? 4:???? <services>?????

?? 5:?????? <service name="Artech.WcfServices.Service.CalculatorService" >

?? 6:???????? <endpoint address="http://127.0.0.1:3721/calculatorservice" binding="ws2007HttpBinding" contract="Artech.WcfServices.Contract.ICalculator" />

?? 7:???????? <endpoint kind="udpDiscoveryEndpoint" endpointConfiguration="wsd11"/>

?? 8:?????? </service>

?? 9:???? </services>

? 10:???? <standardEndpoints>

? 11:?????? <udpDiscoveryEndpoint>

? 12:???????? <standardEndpoint name="wsd11" discoveryVersion="WSDiscovery11"/>

? 13:?????? </udpDiscoveryEndpoint>

? 14:???? </standardEndpoints>

? 15:?? </system.serviceModel>

? 16:?? ...

? 17: </configuration>

读书人网 >编程

热点推荐