成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

WCF異常相關(guān)經(jīng)驗(yàn)分享

開發(fā) 開發(fā)工具
WCF異常在實(shí)際使用中是不可避免的。那么如何才能將WCF異常信息傳遞到客戶端中呢?對于WCF異常的具體含義又有多少人清楚呢?

WCF框架作為一款由微軟開發(fā)的幫助解決跨平臺操作的方案,深受開發(fā)人員喜愛。在這里主要介紹一下WCF異常的相關(guān)知識。希望對大家有用。#t#

WCF異常將服務(wù)異常(Exception)轉(zhuǎn)換成 SOAP faults,傳遞到客戶端后再次轉(zhuǎn)換成 Exception。只不過缺省情況下,我們很難從中獲取有意義的信息。

 

 

  1. < ServiceContract()> _  
  2. Public Interface IService1  
  3. < OperationContract()> _  
  4. Function GetData(ByVal
     value As Integer) As String  
  5.  
  6. End Interface  
  7. Public Class Service1  
  8. Implements IService1  
  9. Public Function GetData(ByVal 
    value As Integer) As String 
    Implements IService1.GetData  
  10. Throw New Exception("發(fā)生錯誤。")  
  11. Return String.Format
    ("You entered: {0}", value)  
  12. End Function  
  13. End Class 

 

拋出來的WCF異常信息:

接收對 http://localhost:8731/Design_Time_Addresses/WcfServiceLibrary1/Service1/ 的 HTTP 響應(yīng)時發(fā)生錯誤。這可能是由于服務(wù)終結(jié)點(diǎn)綁定未使用 HTTP 協(xié)議造成的。這還可能是由于服務(wù)器中止了 HTTP 請求上下文(可能由于服務(wù)關(guān)閉)所致。有關(guān)詳細(xì)信息,請參閱服務(wù)器日志。

 

Server stack trace:

在 System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)

在 System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
 

 

 

不太好理解

當(dāng)然,WCF 會提供一個包裝異常類 FaultException 來幫助我們處理這些問題。

發(fā)生錯誤。

Server stack trace:

在 System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)

在 System.Servi
 

這樣就對WCF異常好理解多了,所以在服務(wù)端拋出異常時,使用FaultException 異常類。

另外,我們還可以通過 FaultContractAttribute 傳遞更詳細(xì)的異常信息給客戶端。

 

 

 

  1. < ServiceContract()> _  
  2. Public Interface IService1  
  3. < OperationContract(), 
    FaultContract(GetType(Fault))
    > _  
  4. Function GetData(ByVal 
    value As Integer) As String  
  5. End Interface  
  6. Public Class Service1  
  7. Implements IService1  
  8. Public Function GetData(
    ByVal value As Integer) As 
    String Implements IService1.GetData  
  9. Dim f As New Fault  
  10. f.ErrorCode = 200 
  11. f.Message = "發(fā)生錯誤" 
  12. Throw New FaultException
    (Of Fault)(f, f.Message)  
  13. Return String.Format("You
     entered: {0}", value)  
  14. End Function  
  15. End Class  
  16. < DataContract()> _  
  17. Public Class Fault  
  18. < DataMember()> _  
  19. Public ErrorCode As Integer  
  20. < DataMember()> _  
  21. Public Message As String
    String = String.Empty  
  22. End Class 

 

 

 

 

 

 

客戶端代碼:

 

  1. Sub Main()  
  2. Dim url As String = "http:/
    /localhost:8731/Design_Time_
    Addresses/WcfServiceLibrary1
    /Service1/mex"
     
  3. Dim host As New System.Servi
    ceModel.ServiceHost(GetType
    (WcfServiceLibrary1.Service1))  
  4. host.AddServiceEndpoint(GetType
    (WcfServiceLibrary1.IService1), 
    New System.ServiceModel.Basic
    HttpBinding(), url)  
  5. host.Open()  
  6. Console.WriteLine(host.State.ToString)  
  7. Dim c = New System.ServiceModel
    .ChannelFactory(Of WcfServiceL
    ibrary1.IService1)(New System.
    ServiceModel.BasicHttpBinding, url)  
  8. Dim s As WcfServiceLibrary1.
    IService1
     = c.CreateChannel  
  9. Try  
  10. Console.WriteLine(s.GetData(1))  
  11. Catch ex As System.ServiceModel.
    FaultException(Of WcfService
    Library1.Fault)  
  12. Console.WriteLine("錯誤代碼:" 
    & ex.Detail.ErrorCode)  
  13. Console.WriteLine("錯誤消息:" 
    & ex.Detail.Message)  
  14. End Try  
  15. Console.ReadKey()  
  16. End Sub 

 

這樣WCF異常信息,就可以傳遞到客戶端了。

責(zé)任編輯:曹凱 來源: 博客園
相關(guān)推薦

2009-12-21 13:27:45

WCF服務(wù)配置信息

2009-12-07 15:02:46

WCF學(xué)習(xí)

2009-12-22 19:26:51

WCF綁定

2009-12-22 13:48:09

引用WCF服務(wù)

2010-02-22 17:58:06

WCF異步上傳

2011-05-16 09:30:30

jQueryWCF

2009-12-22 18:18:11

WCF客戶端編程

2010-02-24 11:22:04

WCF方法重載

2010-02-22 11:10:17

WCF獲取客戶端IP

2017-07-27 17:37:44

MySQL死鎖日志

2010-01-13 18:09:09

VB.NET動態(tài)生成代

2010-02-22 13:35:03

WCF異常處理

2009-12-07 18:33:31

WCF Service

2009-12-08 16:42:48

WCF Service

2010-03-02 17:48:35

WCF尋址報(bào)頭

2009-11-09 17:06:38

WCF選擇綁定

2009-11-09 10:10:13

WCF異常

2009-12-07 18:38:16

WCF異常

2009-11-05 12:45:25

WCF異常

2010-01-07 15:29:59

VB.NET表達(dá)式
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號

主站蜘蛛池模板: 日韩视频一区二区 | 亚洲精品久| 九九综合 | 伊人网综合 | 一本色道精品久久一区二区三区 | 欧美一区二区三区四区视频 | 日韩一级免费大片 | 久久毛片 | 免费在线观看一区二区 | 日韩精品在线观看一区二区三区 | 日本欧美国产在线观看 | 久久久久久久91 | 国产99免费视频 | 亚洲v日韩v综合v精品v | 中文字幕在线看 | 中文字幕亚洲视频 | 免费亚洲成人 | 国产97在线视频 | 男人天堂色 | 午夜影院在线观看 | 国产91丝袜在线播放 | 爱爱爱av| 国产精品嫩草影院精东 | 国产精品夜间视频香蕉 | 精品久久久久久亚洲综合网 | 国产精品久久国产精品 | 国产精品免费大片 | 成人影院在线视频 | 免费一级做a爰片久久毛片潮喷 | www.日韩免费| 亚洲一区在线日韩在线深爱 | .国产精品成人自产拍在线观看6 | 国产日产久久高清欧美一区 | 青春草在线 | 久久精品中文字幕 | 国产亚洲精品久久久久动 | 日韩有码在线播放 | 久久精品色视频 | 青青久在线视频 | 久久午夜电影 | 奇米在线|