zoukankan      html  css  js  c++  java
  • 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 配置成 Off ,服务器端的详细错误异常,才能传递到客户端
         默认是不传递完整的错误异常的。
         -->

    <customErrors mode ="Off" />
      </system.runtime.remoting>

  • 相关阅读:
    新站发布——寻爱交友网
    博客园居然还在运营
    关于Method类的invoke方法
    创建对象的四种方法
    事务操作
    数据库的并发
    run( )和start( )方法
    JAVA语言的下面几种数组复制方法中,哪个效率最高?
    构造函数问题
    上下转型的调用问题
  • 原文地址:https://www.cnblogs.com/wdfrog/p/1214207.html
Copyright © 2011-2022 走看看