日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
關(guān)閉WCF鏈接正確方法詳解

WCF是一款由微軟開發(fā)的有關(guān)通信的一個(gè)開發(fā)框架。它可以為我們創(chuàng)造一個(gè)可靠的,跨平臺的方式。通常情況下我們關(guān)閉WCF鏈接都是簡單地寫把ICommunicationObject.Close()方法。#t#

但是這個(gè)方法有個(gè)問題就是當(dāng)調(diào)用發(fā)生異常時(shí),Close()會發(fā)生次生的異常,導(dǎo)致鏈接不能正常關(guān)閉。如果當(dāng)這種異常很多時(shí),必然對系統(tǒng)的穩(wěn)定性有很大的影響,所以我們必須要考慮異常發(fā)生后如何關(guān)閉鏈接的問題。

我們可以寫一個(gè)擴(kuò)展來專門關(guān)閉WCF鏈接,而不是使用原來的Close

  1. public static void CloseConnection
    (this ICommunicationObject myServiceClient)  
  2. {  
  3. if (myServiceClient.State !=
     CommunicationState.Opened)  
  4. {  
  5. return;  
  6. }  
  7. try  
  8. {  
  9. myServiceClient.Close();  
  10. }  
  11. catch (CommunicationException ex)  
  12. {  
  13. Debug.Print(ex.ToString());  
  14. myServiceClient.Abort();  
  15. }  
  16. catch (TimeoutException ex)  
  17. {  
  18. Debug.Print(ex.ToString());  
  19. myServiceClient.Abort();  
  20. }  
  21. catch (Exception ex)  
  22. {  
  23. Debug.Print(ex.ToString());  
  24. myServiceClient.Abort();  
  25. throw;  
  26. }  

然后可以使用這個(gè)擴(kuò)展來實(shí)現(xiàn)關(guān)閉WCF鏈接:

 
 
 
  1. protected void Close(T client)  
  2. {  
  3. if (client != null)  
  4. {  
  5. IChannel iChannel = client 
    as IChannel;  
  6. if (iChannel != null)  
  7. iChannel.CloseConnection();  
  8. else  
  9. {  
  10. IDisposable iDisposable =
     client as IDisposable;  
  11. if (iDisposable != null) 
    iDisposable.Dispose();  
  12. }  
  13. }  

網(wǎng)站名稱:關(guān)閉WCF鏈接正確方法詳解
分享URL:http://www.5511xx.com/article/dhhsdig.html