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>

  • 相关阅读:
    Cable master--hdu1551(二分法)
    Pie--hdu1969(二分法)
    Ice_cream's world I--hdu2120
    How Many Tables--hdu1213(并查集)
    畅通工程--hdu1232(并查集)
    小希的迷宫--hdu1272(并查集)
    More is better--hdu1856(并查集)
    Windows Message Queue--hdu1509
    期末考试--nyoj-757
    网络开发之使用Web Service和使用WCF服务
  • 原文地址:https://www.cnblogs.com/wdfrog/p/1214207.html
Copyright © 2011-2022 走看看