2011-08-20 49 views
1

我正在處理.Net遠程處理項目。如果遠程對象中有任何異常,我希望將該異常詳細地發送給客戶端。我正在使用下面的代碼來實現這一點 -在.net遠程處理對象中處理異常

'This is on a shared .dll 
Public Interface ICreateNewMouza 
Function CreateNewMouza(ByVal MouzaToCreate As Mouza) As Integer 
End Interface 

Imports System 
Imports System.Runtime.Serialization 

<serializable()> _ 
Public Class CustomException 
Inherits System.ApplicationException 

Public Sub New(ByVal message As String) 
    MyBase.New(message) 
End Sub 

Public Sub New(ByVal info As SerializationInfo, ByVal context As StreamingContext) 
    MyBase.New(info, context) 
End Sub 

Public Overrides Sub GetObjectData(ByVal info As SerializationInfo, ByVal context As StreamingContext) 
    MyBase.GetObjectData(info, context) 
End Sub 
End Class 

'This is remote object which a client will invoke- 

Imports System.Runtime.Remoting 
Imports ClassInterfaces 

Public Class CreateNewMouza 
Inherits MarshalByRefObject 
Implements ClassInterfaces.ICreateNewMouza 

Public Function CreateNewMouza(ByVal MouzaToCreate As ClassInterfaces.Mouza) As Integer Implements ClassInterfaces.ICreateNewMouza.CreateNewMouza 
    Try 
     ' some code 
    Catch ex As Exception 
     ## what should be here? 
    End Try 

End Function 
End Class 

什麼應該在try .. catch塊?我錯過了別的嗎? 請幫幫我。

在此先感謝 SKPaul

回答

0

你明白了就在那裏 - 你會趕上例外是RemotingException。我一直傾向於WCF進行遠程處理,但看起來你已經在示例中正確設置了它。

您是否遇到特定問題,或者某些問題無法正常工作,或者您只是在出於好奇而提出設置問題?

+0

親愛的rwmnau, 首先,我無法將異常發送到客戶端。但是我能夠收集該遠程對象中的異常。現在,如何發送給客戶?也許,我不知道正確的做法。 –

+0

@SKPaul。只需將您的自定義異常放入Try/Catch塊即可。您的客戶端將收到類型CustomException的異常。要向你的異常添加額外的信息,請向你的類添加一個屬性,並在相關的函數/構造函數中序列化/反序列化它。 – Hans

+0

Hansjoerg, 我不想拋出任何異常。但是如果發生任何異常,我想抓住並傳達給客戶。希望,你已經意識到我的意圖。 –