/// <summary>
        /// 解析Message的头
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        public static ExceptionSoapHeader FromReader(XmlDictionaryReader reader)
        {
            ExceptionSoapHeader header = new ExceptionSoapHeader();
            while (!reader.EOF)
            {
                reader.Read();
                if (reader.Name == "type" && reader.IsStartElement())
                    header.ExceptionType = (SoapExceptionType)Enum.Parse(typeof(SoapExceptionType), reader.ReadElementContentAsString());
                else if (reader.Name == "message" && reader.IsStartElement())
                    header.Message = reader.ReadElementContentAsString();
                else if (reader.Name == "stack" && reader.IsStartElement())
                    header.Stack = reader.ReadElementContentAsString();
                else if (reader.Name == "appversion" && reader.IsStartElement())
                    header.AppVersion = reader.ReadElementContentAsString();
                else
                    continue;
                
            }

            return header;
        }
        /// <summary>
        /// 将错误写入Message的头部
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="type"></param>
        /// <param name="msgBody"></param>
        public static void WriteHeader(Message msg, Exception error)
        {
            ExceptionSoapHeader header = new ExceptionSoapHeader();
            SoapExceptionType errorType = SoapExceptionType.Application;

            if (error is AuthenticationException)
                errorType = SoapExceptionType.UnAuthenticated;
            else if (error is UnauthorizedAccessException)
                errorType = SoapExceptionType.UnAuthorized;
            else if (error is DataException)
                errorType = SoapExceptionType.DataAccess;
            else if (error is TimeoutException)
                errorType = SoapExceptionType.TimeOut;

            header.ExceptionType = errorType;
            header.Message = error.Message;
#if(DEBUG)
            header.Stack = error.StackTrace;
#endif
            msg.Headers.Add(header);
        }