配置WCF服務(wù)HTTP-GET元數(shù)據(jù)交換方式案例分析
WCF經(jīng)過長(zhǎng)時(shí)間的發(fā)展,很多用戶都很了解WCF了,這里我發(fā)表一下個(gè)人理解,和大家討論討論關(guān)于WCF服務(wù)元數(shù)據(jù)交換配置實(shí)現(xiàn)過程。WCF與其他面向服務(wù)技術(shù)之間(asp.net \j2ee Web Service技術(shù)等)最大的區(qū)別在于傳輸可靠性(Transport Reliability)與消息可靠性(Message Reliability)。傳輸可靠性(例如通過TCP傳輸)在網(wǎng)絡(luò)數(shù)據(jù)包層提供了點(diǎn)對(duì)點(diǎn)保證傳遞(Point-to-Point Guaranteed Delivery),以確保數(shù)據(jù)包的順序無誤。傳輸可靠性不會(huì)受到網(wǎng)絡(luò)連接的中斷或其他通信問題的影響。
#T#消息可靠性提供了端對(duì)端保證傳遞(End-to- End Guaranteed Delivery),確保消息的順序無誤。消息可靠性與引入的中間方的數(shù)量無關(guān),與網(wǎng)絡(luò)跳數(shù)(Network Hops)的數(shù)量也沒有關(guān)聯(lián)。消息可靠性基于一個(gè)行業(yè)標(biāo)準(zhǔn)。該行業(yè)標(biāo)準(zhǔn)為可靠的基于消息的通信維持了一個(gè)在傳輸層的會(huì)話。如果傳輸失敗,例如無線連接中斷,消息可靠性就會(huì)重試(Retries)功能。它還能夠自動(dòng)處理網(wǎng)絡(luò)阻(Congestion)、消息緩存(Message Buffering)以及流控制(Flow Control),根據(jù)具體情況適時(shí)調(diào)整發(fā)送的消息數(shù)。消息可靠性還能夠通過對(duì)連接的驗(yàn)證管理連接自身,并在不需要連接時(shí)清除它們。
配置WCF服務(wù)HTTP-GET元數(shù)據(jù)交換方式
需要配置WCF服務(wù)的行為和基地址,客戶端可以根據(jù)基地址查看服務(wù)的元數(shù)據(jù)。代碼如下:
- <service name="WcfServiceApp.WCFService" behaviorConfiguration="WcfServiceApp.WCFServiceBehavior">
- <host>
- <baseAddresses>
- <add baseAddress="http://localhost:8001/"/>
- </baseAddresses>
- </host>
- </service>
- </services>
- <behaviors>
- <serviceBehaviors>
- <behavior name="WcfServiceApp.WCFServiceBehavior">
- <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
- <serviceMetadata httpGetEnabled="true"/>
- <!-- To receive exception details in faults for debugging purposes, set the value below to true.Set to false before deployment to avoid disclosing exception information -->
- <serviceDebug includeExceptionDetailInFaults="false"/>
- </behavior>
- </serviceBehaviors>
- </behaviors>
配置WCF服務(wù)完成以后,我們可以使用基地址在瀏覽器里查看服務(wù)的信息,效果如下圖: