处理.NET远程对象中的异常 [英] Handle exceptions in .net remote objects

查看:54
本文介绍了处理.NET远程对象中的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友,

我正在从事.Net Remoting项目.如果远程对象中有任何异常,我想将此异常详细发送给客户端.我正在使用以下代码来实现这一目标-

Dear Friends,

I am working on a .Net Remoting project. If there is any exception in remote object, I would like to send this exception in detail to the client. I am using the following code to accomplish that-

'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




What should be in the try.. catch block?
Please help me.

Thanks in advance
SKPaul

推荐答案

如果您正在使用WCF服务,则
If you are using WCF services, then
[FaultContract] 

是满足您需求的最佳解决方案.

如果itz只是一个Web服务,则可以从服务器端返回异常代码.客户端代码可以解释为显示适当的用户消息.

is the best solution for your requirement.

If itz just a web service, you can return the exception code from the server side. Client code can interpret to show the appropriate user message.


这篇关于处理.NET远程对象中的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆