Remoting 错误信息类序列化问题


   在使用Remoting技术时,如果需要使用自己定义错误类即不是简单的使用Exception类时,自定义类除了要从Exception继承外,还要实现序列化接口,才可以使用,下面定义了SyncException类
------

    public enum SyncExceptionTypes { FileNotExists = 0, FileAccessError = 1, AuditError = 2, }

    [Serializable]
    public class SyncException : Exception, ISerializable
    {
        #region 属性
        SyncExceptionTypes _exceptionType;
        public SyncExceptionTypes ExceptionType
        {
            get { return _exceptionType; }
        }
        #endregion

        protected SyncException(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
            this._exceptionType = (SyncExceptionTypes)info.GetValue("ExceptionType", typeof(SyncExceptionTypes));
        }
        public SyncException(string msg, SyncExceptionTypes type)
            : base(msg)
        {
            _exceptionType = type;
        }


        #region ISerializable 成员

        void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
        {
            //调用父类的序列化以保存数据
            base.GetObjectData(info, context);
            info.AddValue("ExceptionType", _exceptionType, typeof(SyncExceptionTypes));
        }

        #endregion
    }
--------------
  最后注意在服务端配置文件里做关闭客户端错误
<system.runtime.remoting>
.......................
 
<customErrors mode ="Off" />
  system.runtime.remoting>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值