簡化了配置文件
當(dāng)在Visual Studio 添加服務(wù)引用或者用SvcUtil.exe(配置文件客戶端)工具生成的時(shí)候,在以前的WCF版本中,這些配置文件包含了所有的綁定屬性即使它是默認(rèn)值。在WCF的4.5版本以后,這些配置文件只包含設(shè)置過的非默認(rèn)值的屬性。
WCF 3.0 以前配置文件:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false"
hostNameComparisonMode="StrongWildcard" maxBufferSize="65536"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192"
maxArrayLength="16384" maxBytesPerRead="4096"
maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:36906/Service1.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService1" contract="IService1"
name="BasicHttpBinding_IService1" />
</client>
</system.serviceModel>
</configuration>
WCF 4.5以后配置文件:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:36906/Service1.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService1" contract="IService1"
name="BasicHttpBinding_IService1" />
</client>
</system.serviceModel>
</configuration>
契約優(yōu)先開發(fā)模式
現(xiàn)在WCF支持契約優(yōu)先開發(fā)模式。svcutl.exe工具包含一個(gè)服務(wù)契約轉(zhuǎn)換按鈕,允許你來選擇從WSDL生成服務(wù)或者數(shù)據(jù)契約。
從一個(gè)可移植的子集項(xiàng)目中添加服務(wù)引用
可移植的子集項(xiàng)目可以讓開發(fā)者在支持多個(gè)平臺(tái)(desktop, Silverlight, Windows Phone, and XBOX)的同時(shí)維護(hù)一個(gè)資源樹和生成系統(tǒng)??梢浦驳淖蛹?xiàng)目僅引用了.NET可移植庫,它是一個(gè)可以在任何.NET平臺(tái)使用的框架。開發(fā)者可以按照添加WCF客戶端應(yīng)用程序的方法來添加一個(gè)服務(wù)引用。更多信息請參考:從一個(gè)可移植的子集項(xiàng)目中添加服務(wù)引用
ASP.NET兼容模式默認(rèn)的改變
ASP.NET兼容模式可以讓開發(fā)者獲得管道的全部功能。使用兼容模式時(shí) ,必須在web.config文件中將<serviceHostingEnvironment>節(jié)點(diǎn)下的aspNetCompatibilityEnabled屬性設(shè)置為true,另外,在應(yīng)用程序域中所有的服務(wù)必須有RequirementsMode屬性,并且將AspNetCompatiliblityRequirementsAttribute設(shè)置為Allowed或者Required,默認(rèn)AspNetCompatiliblityRequirementsAttribute值為Allowed,并且WCF服務(wù)應(yīng)用模板將aspNetCompatibilityEnabled設(shè)置為true.更多信息請參考:WCF中的新功能和WCF服務(wù)和ASP.NET
流的改進(jìn)
-
WCF新增加了支持異步流。為了實(shí)現(xiàn)異步流,需要在服務(wù)宿主中添加終結(jié)點(diǎn)DispatcherSynchronizationBehavior,并且將AsynchronousSendEnabled屬性設(shè)置為true。當(dāng)多個(gè)客戶端在這個(gè)服務(wù)讀取流時(shí)會(huì)有所幫助。這樣WCF不會(huì)阻塞一個(gè)客戶端線程。 - 當(dāng)用
IIS托管服務(wù)的時(shí)候,刪除了緩存消息的限制。在以前的WCF版本中,當(dāng)IIS服務(wù)器接收到消息時(shí)(用流消息傳輸),ASP.NET會(huì)將整個(gè)消息在發(fā)給WCF之前緩存下來,這樣講消耗掉大量內(nèi)存。這個(gè)緩存機(jī)制在.NET4.5被取消,現(xiàn)在IIS托管的WCF服務(wù)可以在信息未完全接受完之前進(jìn)行處理,從而實(shí)現(xiàn)真正的流,這使WCF響應(yīng)更快,并且提高了性能。另外,不需要設(shè)置maxRequestLength,如果設(shè)置了,也會(huì)被忽略掉。更多有關(guān)maxRequestLength的信息請參考:http運(yùn)行時(shí)元素配置(<httpRuntime> configuration element),還需要配置maxAllowedContentLength,更多信息參考:IIS請求限制(IIS Request Limits)