Exemplo n.º 1
0
            public override void AfterReceiveReply(ref Message reply, object correlationState)
            {
                bool callBase = true;

                if (reply != null)
                {
                    object responseProperty = reply.Properties[HttpResponseMessageProperty.Name];
                    if (responseProperty != null)
                    {
                        if (((HttpResponseMessageProperty)responseProperty).Headers[JsonGlobals.jsonerrorString] == JsonGlobals.trueString)
                        {
                            callBase = false;
                            XmlDictionaryReader reader      = reply.GetReaderAtBodyContents();
                            JsonFaultDetail     faultDetail = jsonFaultSerializer.ReadObject(reader) as JsonFaultDetail;
                            FaultCode           faultCode   = new FaultCode(FaultCodeConstants.Codes.InternalServiceFault, FaultCodeConstants.Namespaces.NetDispatch);
                            faultCode = FaultCode.CreateReceiverFaultCode(faultCode);
                            if (faultDetail != null)
                            {
                                if (faultDetail.ExceptionDetail != null)
                                {
                                    throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                                              new FaultException <ExceptionDetail>(faultDetail.ExceptionDetail, faultDetail.Message, faultCode));
                                }
                                else
                                {
                                    throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                                              new FaultException(MessageFault.CreateFault(faultCode, faultDetail.Message)));
                                }
                            }
                            else
                            {
                                throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                                          new FaultException(MessageFault.CreateFault(faultCode,
                                                                                      System.ServiceModel.SR.GetString(System.ServiceModel.SR.SFxInternalServerError))));
                            }
                        }
                    }
                }
                if (callBase)
                {
                    base.AfterReceiveReply(ref reply, correlationState);
                }
            }
Exemplo n.º 2
0
 public JsonFaultBodyWriter(MessageFault fault, bool includeExceptionDetailInFaults)
     : base(false)
 {
     faultDetail = new JsonFaultDetail();
     if (includeExceptionDetailInFaults)
     {
         faultDetail.Message = fault.Reason.ToString();
         if (fault.HasDetail)
         {
             try
             {
                 ExceptionDetail originalFaultDetail = fault.GetDetail <ExceptionDetail>();
                 faultDetail.StackTrace      = originalFaultDetail.StackTrace;
                 faultDetail.ExceptionType   = originalFaultDetail.Type;
                 faultDetail.ExceptionDetail = originalFaultDetail;
             }
             catch (SerializationException exception)
             {
                 System.ServiceModel.DiagnosticUtility.TraceHandledException(exception, TraceEventType.Information);
                 // A SerializationException will be thrown if the detail isn't of type ExceptionDetail
                 // In that case, we want to just move on.
             }
             catch (SecurityException exception)
             {
                 System.ServiceModel.DiagnosticUtility.TraceHandledException(exception, TraceEventType.Information);
                 // A SecurityException will be thrown if the detail can't be obtained in partial trust
                 // (This is guaranteed to happen unless there's an Assert for MemberAccessPermission, since ExceptionDetail
                 //     has DataMembers that have private setters.)
                 // In that case, we want to just move on.
             }
         }
     }
     else
     {
         faultDetail.Message = System.ServiceModel.SR.GetString(System.ServiceModel.SR.SFxInternalServerError);
     }
 }
 public JsonFaultBodyWriter(MessageFault fault, bool includeExceptionDetailInFaults)
     : base(false)
 {
     faultDetail = new JsonFaultDetail();
     if (includeExceptionDetailInFaults)
     {
         faultDetail.Message = fault.Reason.ToString();
         if (fault.HasDetail)
         {
             try
             {
                 ExceptionDetail originalFaultDetail = fault.GetDetail<ExceptionDetail>();
                 faultDetail.StackTrace = originalFaultDetail.StackTrace;
                 faultDetail.ExceptionType = originalFaultDetail.Type;
                 faultDetail.ExceptionDetail = originalFaultDetail;
             }
             catch (SerializationException exception)
             {
                 System.ServiceModel.DiagnosticUtility.TraceHandledException(exception, TraceEventType.Information);
                 // A SerializationException will be thrown if the detail isn't of type ExceptionDetail
                 // In that case, we want to just move on.
             }
             catch (SecurityException exception)
             {
                 System.ServiceModel.DiagnosticUtility.TraceHandledException(exception, TraceEventType.Information);
                 // A SecurityException will be thrown if the detail can't be obtained in partial trust
                 // (This is guaranteed to happen unless there's an Assert for MemberAccessPermission, since ExceptionDetail
                 //     has DataMembers that have private setters.)
                 // In that case, we want to just move on.
             }
         }
     }
     else
     {
         faultDetail.Message = System.ServiceModel.SR.GetString(System.ServiceModel.SR.SFxInternalServerError);
     }
 }