配置WCF服務HTTP-GET元數據交換方式案例分析
WCF經過長時間的發展,很多用戶都很了解WCF了,這里我發表一下個人理解,和大家討論討論關于WCF服務元數據交換配置實現過程。WCF與其他面向服務技術之間(asp.net \j2ee Web Service技術等)最大的區別在于傳輸可靠性(Transport Reliability)與消息可靠性(Message Reliability)。傳輸可靠性(例如通過TCP傳輸)在網絡數據包層提供了點對點保證傳遞(Point-to-Point Guaranteed Delivery),以確保數據包的順序無誤。傳輸可靠性不會受到網絡連接的中斷或其他通信問題的影響。
#T#消息可靠性提供了端對端保證傳遞(End-to- End Guaranteed Delivery),確保消息的順序無誤。消息可靠性與引入的中間方的數量無關,與網絡跳數(Network Hops)的數量也沒有關聯。消息可靠性基于一個行業標準。該行業標準為可靠的基于消息的通信維持了一個在傳輸層的會話。如果傳輸失敗,例如無線連接中斷,消息可靠性就會重試(Retries)功能。它還能夠自動處理網絡阻(Congestion)、消息緩存(Message Buffering)以及流控制(Flow Control),根據具體情況適時調整發送的消息數。消息可靠性還能夠通過對連接的驗證管理連接自身,并在不需要連接時清除它們。
配置WCF服務HTTP-GET元數據交換方式
需要配置WCF服務的行為和基地址,客戶端可以根據基地址查看服務的元數據。代碼如下:
- <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服務完成以后,我們可以使用基地址在瀏覽器里查看服務的信息,效果如下圖: