Ejemplo n.º 1
0
        public void ProvideFault(Exception error, System.ServiceModel.Channels.MessageVersion version, ref System.ServiceModel.Channels.Message fault)
        {
            string errName = string.Format("调用 {0} 时异常", OperationContext.Current.IncomingMessageProperties["HttpOperationName"]);

            WfErrorDTO errorDTO = new WfErrorDTO()
            {
                Number = 100,
                Name = errName,
                Message = error.Message,
                Description = error.StackTrace
            };

            string jsonResult = string.Empty;

            try
            {
                jsonResult = JSONSerializerExecute.SerializeWithType(errorDTO);
            }
            catch (InvalidOperationException)
            {
                errorDTO.Description = string.Empty;
                jsonResult = JSONSerializerExecute.SerializeWithType(errorDTO);
            }

            fault = WcfUtils.CreateJsonFormatReplyMessage(version, null, jsonResult);
        }
Ejemplo n.º 2
0
        public void ProvideFault(Exception error, System.ServiceModel.Channels.MessageVersion version, ref System.ServiceModel.Channels.Message fault)
        {
            string errName = string.Format("调用 {0} 时异常", OperationContext.Current.IncomingMessageProperties["HttpOperationName"]);

            WfErrorDTO errorDTO = new WfErrorDTO()
            {
                Number      = 100,
                Name        = errName,
                Message     = error.Message,
                Description = error.StackTrace
            };

            string jsonResult = string.Empty;

            try
            {
                jsonResult = JSONSerializerExecute.SerializeWithType(errorDTO);
            }
            catch (InvalidOperationException)
            {
                errorDTO.Description = string.Empty;
                jsonResult           = JSONSerializerExecute.SerializeWithType(errorDTO);
            }

            fault = WcfUtils.CreateJsonFormatReplyMessage(version, null, jsonResult);
        }
Ejemplo n.º 3
0
        public override object Deserialize(IDictionary <string, object> dictionary, Type type, JavaScriptSerializer serializer)
        {
            WfErrorDTO error = new WfErrorDTO();

            error.Name        = DictionaryHelper.GetValue(dictionary, "name", string.Empty);
            error.Message     = DictionaryHelper.GetValue(dictionary, "message", string.Empty);
            error.Description = DictionaryHelper.GetValue(dictionary, "description", string.Empty);
            error.Number      = DictionaryHelper.GetValue(dictionary, "number", 0);

            return(error);
        }
Ejemplo n.º 4
0
		public override object Deserialize(IDictionary<string, object> dictionary, Type type, JavaScriptSerializer serializer)
		{
			WfErrorDTO error = new WfErrorDTO();

			error.Name = DictionaryHelper.GetValue(dictionary, "name", string.Empty);
			error.Message = DictionaryHelper.GetValue(dictionary, "message", string.Empty);
			error.Description = DictionaryHelper.GetValue(dictionary, "description", string.Empty);
			error.Number = DictionaryHelper.GetValue(dictionary, "number", 0);

			return error;
		}
Ejemplo n.º 5
0
        public override IDictionary <string, object> Serialize(object obj, JavaScriptSerializer serializer)
        {
            Dictionary <string, object> dictionary = new Dictionary <string, object>();
            WfErrorDTO error = (WfErrorDTO)obj;

            DictionaryHelper.AddNonDefaultValue <string, object>(dictionary, "name", error.Name);
            DictionaryHelper.AddNonDefaultValue <string, object>(dictionary, "message", error.Message);
            DictionaryHelper.AddNonDefaultValue <string, object>(dictionary, "description", error.Description);
            DictionaryHelper.AddNonDefaultValue <string, object>(dictionary, "number", error.Number);

            return(dictionary);
        }
Ejemplo n.º 6
0
        public void AfterReceiveReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
        {
            XmlDocument document = null;

            Message relayMessage = WcfUtils.SimpleCloneMessage(reply, out document);

            string jsonStr = WcfUtils.GetMessageRawContent(document);

            if (jsonStr.IsNotEmpty())
            {
                if (jsonStr.IndexOf("MCS.Library.WcfExtensions.WfErrorDTO") >= 0)
                {
                    WfErrorDTO error = JSONSerializerExecute.Deserialize <WfErrorDTO>(jsonStr);

                    throw new WfClientChannelException(error.Message)
                          {
                              Detail = error.Description
                          };
                }
            }

            reply = relayMessage;
        }