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);
        }
        public System.ServiceModel.Channels.Message SerializeReply(System.ServiceModel.Channels.MessageVersion messageVersion, object[] parameters, object result)
        {
            Message returnMessage = null;

            PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration("SerializeReply", () =>
            {
                //返回值总是Raw格式的
                string jsonResult = string.Empty;

                if (result is string)
                {
                    if (this._AtlasEnabled)
                    {
                        //asp.net ajax 返回值格式
                        Dictionary <string, object> returnDict = new Dictionary <string, object>();
                        returnDict.Add("d", result);
                        jsonResult = JSONSerializerExecute.Serialize(returnDict);
                    }
                    else
                    {
                        jsonResult = result.ToString();
                    }
                }
                else
                {
                    jsonResult = JSONSerializerExecute.SerializeWithType(result);
                }

                returnMessage = WcfUtils.CreateJsonFormatReplyMessage(messageVersion, this._OperationDesc.Messages[1].Action, jsonResult);
            });

            return(returnMessage);
        }