在Net Remoting中,远程对象中自定义的Exception继承于ApplicationException, 这样就无法再继承于MarshalByRefObject, 那怎么将自定义的Exception传到客户端呢?
使用 Remoting 异常,最好将异常类标记为可序列化的并实现 ISerializable 接口。这样,可以跨 Remoting 边界对异常进行正确地序列化,也可以在构造过程中将自定义的数据添加到异常中。对于需要远程处理以及在使用中要保持一致的异常,最好定义您自己的异常类。确保使用此方法能捕获所有异常并进行正确传播,而且不允许未处理的异常跨过 Remoting 边界。
[Serializable()]
public class myexcption : System.Exception,ISerializable
{
public myexcption( string Msg , Exception inner ):base( Msg , inner )
{}
public myexcption():base()
{}
public myexcption( string Msg ):base(Msg)
{
}
protected myexcption(SerializationInfo info, StreamingContext context):base( info , context )
{
}
[SecurityPermissionAttribute(SecurityAction.Demand,SerializationFormatter
=true)]
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData( info , context );
}
}
异常应当支持序列化
异常是支持序列化的。
如果是自定义的,要加上 [Serializable()] 标志。
然后就可直接通过Remoting.
up
up
www.moblog.net.cn/sunshine.htm
用这个软件 就不需要学Remoting了