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

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

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
為你解決WCF異常問(wèn)題

WCF還是比較常用的,于是我研究了一下WCF,在這里拿出來(lái)和大家分享一下,希望對(duì)大家有用。異常消息與特定技術(shù)有關(guān),.NET異常同樣如此,因而WCF并不支持傳統(tǒng)的異常處理方式。如果在WCF服務(wù)中采用傳統(tǒng)的方式處理異常,由于異常消息不能被序列化,因而客戶端無(wú)法收到服務(wù)拋出的WCF異常,例如這樣的服務(wù)設(shè)計(jì):

創(chuàng)新互聯(lián)建站主營(yíng)安陽(yáng)網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,成都APP應(yīng)用開(kāi)發(fā),安陽(yáng)h5成都微信小程序搭建,安陽(yáng)網(wǎng)站營(yíng)銷推廣歡迎安陽(yáng)等地區(qū)企業(yè)咨詢

 
 
  1. [ServiceContract(SessionModeSessionMode = SessionMode.Allowed)] 
  2. public interface IDocumentsExplorerService 
  3. [OperationContract] 
  4. DocumentList FetchDocuments(string homeDir); 
  5. [ServiceBehavior(InstanceContextModeInstanceContextMode=InstanceContextMode.Single)] 
  6. public class DocumentsExplorerService : IDocumentsExplorerService,IDisposable 
  7. public DocumentList FetchDocuments(string homeDir) 
  8. //Some Codes 
  9. if (Directory.Exists(homeDir)) 
  10. //Fetch documents according to homedir 
  11. else 
  12. throw new DirectoryNotFoundException( 
  13. string.Format("Directory {0} is not found.",homeDir)); 
  14. public void Dispose() 
  15. Console.WriteLine("The service had been disposed."); 

則客戶端在調(diào)用如上的服務(wù)操作時(shí),如果采用如下的捕獲方式是無(wú)法獲取該WCF異常的:

 
 
  1. catch (DirectoryNotFoundException ex) 
  2. //handle the exception; 

為了彌補(bǔ)這一缺陷,WCF會(huì)將無(wú)法識(shí)別的異常均當(dāng)作為FaultException異常對(duì)象,因此,客戶端可以捕獲FaultException或者Exception異常:

 
 
  1. catch (FaultException ex) 
  2. //handle the exception; 
  3. catch (Exception ex) 
  4. //handle the exception; 

#T#然而,這樣捕獲的WCF異常,卻無(wú)法識(shí)別DirectoryNotFoundException所傳遞的錯(cuò)誤信息。尤為嚴(yán)重的是這樣的異常處理方式還會(huì)導(dǎo)致傳遞消息的通道出現(xiàn)錯(cuò)誤,當(dāng)客戶端繼續(xù)調(diào)用該服務(wù)代理對(duì)象的服務(wù)操作時(shí),會(huì)獲得一個(gè)CommunicationObjectFaultedException 異常,無(wú)法繼續(xù)使用服務(wù)。如果服務(wù)被設(shè)置為PerSession模式或者Single模式,異常還會(huì)導(dǎo)致服務(wù)對(duì)象被釋放,終止服務(wù)。

 
 
  1. [ServiceContract(SessionModeSessionMode = SessionMode.Allowed)] 
  2. public interface IDocumentsExplorerService 
  3. [OperationContract] 
  4. [FaultContract(typeof(DirectoryNotFoundException))] 
  5. DocumentList FetchDocuments(string homeDir); 

新聞名稱:為你解決WCF異常問(wèn)題
標(biāo)題網(wǎng)址:http://www.5511xx.com/article/dhgpjhp.html