public void TestCreateMessageFault () { FaultException<int> e = new FaultException<int> (0); Assert.IsFalse ( (object) MessageFault.CreateFault (e.Code, e.Reason, e.Detail) == e.CreateMessageFault (), "#1"); AreMessageFaultEqual ( MessageFault.CreateFault (e.Code, e.Reason, e.Detail), e.CreateMessageFault (), "#2"); }
public void ProvideFault(Exception error, MessageVersion version, ref Message fault) { var newEx = new FaultException(string.Format("服务端错误 {0}", error.TargetSite.Name)); MessageFault msgFault = newEx.CreateMessageFault(); fault = Message.CreateMessage(version, msgFault, newEx.Action); }
/// <summary> /// Enables the creation of a custom System.ServiceModel.FaultException{TDetail} /// that is returned from an exception in the course of a service method. /// </summary> /// <param name="error">The System.Exception object thrown in the course of the service operation.</param> /// <param name="version">The SOAP version of the message.</param> /// <param name="fault">The System.ServiceModel.Channels.Message object that is returned to the client, or service in duplex case</param> public void ProvideFault(Exception error, System.ServiceModel.Channels.MessageVersion version, ref System.ServiceModel.Channels.Message fault) { if (error is FaultException<ApplicationServiceError>) { MessageFault messageFault = ((FaultException<ApplicationServiceError>)error).CreateMessageFault(); //propagate FaultException fault = Message.CreateMessage(version, messageFault, ((FaultException<ApplicationServiceError>)error).Action); } else { //create service error ApplicationServiceError defaultError = new ApplicationServiceError() { ErrorMessage = Resources.Messages.message_DefaultErrorMessage }; //Create fault exception and message fault FaultException<ApplicationServiceError> defaultFaultException = new FaultException<ApplicationServiceError>(defaultError); MessageFault defaultMessageFault = defaultFaultException.CreateMessageFault(); //propagate FaultException fault = Message.CreateMessage(version, defaultMessageFault, defaultFaultException.Action); } }
void IErrorHandler.ProvideFault(Exception error, MessageVersion version, ref Message fault) { this.ErrorGuid = Guid.NewGuid(); FaultException<ExceptionDetail> faultException = new FaultException<ExceptionDetail>(new ExceptionDetail(error) { Message = this.ErrorGuid.ToString() }, new FaultReason("ServiceError")); MessageFault messageFault = faultException.CreateMessageFault(); fault = Message.CreateMessage(version, messageFault, faultException.Action); }
/// <summary> /// Enables the creation of a custom System.ServiceModel.FaultException{TDetail} /// that is returned from an exception in the course of a service method. /// </summary> /// <param name="error">The System.Exception object thrown in the course of the service operation.</param> /// <param name="version">The SOAP version of the message.</param> /// <param name="fault"> /// The System.ServiceModel.Channels.Message object that is returned to the client, or service in /// duplex case /// </param> public void ProvideFault(Exception error, MessageVersion version, ref Message fault) { if (error is FaultException<ApplicationServiceError>) { var messageFault = ((FaultException<ApplicationServiceError>) error).CreateMessageFault(); //propagate FaultException fault = Message.CreateMessage( version, messageFault, ((FaultException<ApplicationServiceError>) error).Action); } else { //create service error var defaultError = new ApplicationServiceError() { ErrorMessage = Messages.message_DefaultErrorMessage }; //Create fault exception and message fault var defaultFaultException = new FaultException<ApplicationServiceError>(defaultError); var defaultMessageFault = defaultFaultException.CreateMessageFault(); //propagate FaultException fault = Message.CreateMessage(version, defaultMessageFault, defaultFaultException.Action); } }
/// <summary> /// Allows to add, modify, or suppress a fault message that is generated in response to an exception. /// </summary> /// <param name="error"></param> /// <param name="version"></param> /// <param name="fault"></param> public void ProvideFault(Exception error, MessageVersion version, ref Message fault) { FaultException<PricingException> faultException = new FaultException<PricingException>(new PricingException(error.Message,error.InnerException)); MessageFault messageFault = faultException.CreateMessageFault(); fault = Message.CreateMessage(version, messageFault, faultException.Action); }
/// <summary> /// Enables the creation of a custom <see cref="T:System.ServiceModel.FaultException`1"/> that is returned from an exception in the course of a service method. /// </summary> /// <param name="error"> /// The <see cref="T:System.Exception"/> object thrown in the course of the service operation. /// </param> /// <param name="version"> /// The SOAP version of the message.</param> /// <param name="fault"> /// The <see cref="T:System.ServiceModel.Channels.Message"/> object that is returned to the client, or service, in the duplex case. /// </param> public void ProvideFault(Exception error, MessageVersion version, ref Message fault) { // Shield the unknown exception var faultException = new FaultException("Server error encountered. All details have been logged."); var messageFault = faultException.CreateMessageFault(); fault = Message.CreateMessage(version, messageFault, faultException.Action); }
public void ProvideFault(Exception error, MessageVersion version, ref Message fault) { if (error is FaultException) return; FaultException faultException = new FaultException("A general service error occured"); MessageFault messageFault = faultException.CreateMessageFault(); fault = Message.CreateMessage(version, messageFault, null); }
// Provide a fault. The Message fault parameter can be replaced, or set to null to suppress // reporting a fault. public void ProvideFault(Exception error, MessageVersion version, ref Message fault) { var newEx = new FaultException( $"Exception caught at GlobalErrorHandler{Environment.NewLine}Method: {error.TargetSite.Name}{Environment.NewLine}Message:{error.Message}"); var msgFault = newEx.CreateMessageFault(); fault = Message.CreateMessage(version, msgFault, newEx.Action); }
/// <summary> /// ProvideFault /// </summary> /// <param name="ex">ex</param> /// <param name="version">version</param> /// <param name="msg">msg</param> public void ProvideFault(Exception ex, MessageVersion version, ref Message msg) { //// 写入log4net //log.Error("WCF异常", ex); Logging.LogHelper.WriteError(string.Empty, "WCF异常", ex); var newEx = new FaultException(string.Format("WCF接口出错 {0}", ex.TargetSite.Name)); MessageFault msgFault = newEx.CreateMessageFault(); msg = Message.CreateMessage(version, msgFault, newEx.Action); }
// Provide a fault. The Message fault parameter can be replaced, or set to // null to suppress reporting a fault. public void ProvideFault(Exception error, MessageVersion version, ref Message fault) { var newEx = new FaultException( string.Format("Exception caught at GlobalErrorHandler{0}Method: {1}{2}Message:{3}", Environment.NewLine, error.TargetSite.Name, Environment.NewLine, error.Message)); MessageFault msgFault = newEx.CreateMessageFault(); fault = Message.CreateMessage(version, msgFault, newEx.Action); }
public void ProvideFault(Exception error, MessageVersion version, ref Message fault) { if (error is FaultException) return; if (!error.GetType().IsSerializable) return; FaultException<GeneralServerFault> faultExc = new FaultException<GeneralServerFault>(new GeneralServerFault(error), new FaultReason("Server Level Error")); MessageFault messageFault = faultExc.CreateMessageFault(); fault = Message.CreateMessage(version, messageFault, faultExc.Action); }
public void ProvideFault(Exception error, MessageVersion version, ref Message fault) { if (fault == null) { var fe = new FaultException<FaultException>(new FaultException(error.StackTrace)); var mf = fe.CreateMessageFault(); fault = Message.CreateMessage(version, mf, fe.Action); } }
/// <summary> /// ProvideFault /// </summary> /// <param name="ex">ex</param> /// <param name="version">version</param> /// <param name="msg">msg</param> public void ProvideFault(Exception ex, MessageVersion version, ref Message msg) { Loger.Error("Wcf异常", ex); //// 写入log4net //log.Error("WCF异常", ex); var newEx = new FaultException(string.Format("WCF接口出错 {0}", ex.TargetSite.Name + "=>msg:" + ex.Message)); MessageFault msgFault = newEx.CreateMessageFault(); msg = Message.CreateMessage(version, msgFault, newEx.Action); }
public void ProvideFault(Exception error, MessageVersion version, ref Message fault) { ValidationException validationException = error as ValidationException; if (validationException != null) { FaultException<string> faultException = new FaultException<string>("Error: " + validationException.ValidationResult.ErrorMessage); MessageFault messageFault = faultException.CreateMessageFault(); fault = Message.CreateMessage(version, messageFault, null); } }
public void ProvideFault(Exception error, MessageVersion version, ref Message fault) { var realException = GetRealException(error); FaultException fe = new FaultException(realException.Message); MessageFault messageFault = fe.CreateMessageFault(); fault = Message.CreateMessage(version, messageFault, "http://microsoft.wcf.documentation/default"); HttpResponseMessageProperty property = new HttpResponseMessageProperty(); property.StatusCode = System.Net.HttpStatusCode.OK; fault.Properties[HttpResponseMessageProperty.Name] = property; }
public void ProvideFault(Exception error, System.ServiceModel.Channels.MessageVersion version, ref System.ServiceModel.Channels.Message fault) { if (error is FaultException) { return; } var faultException = new FaultException("An Error Occurred"); var mfault = faultException.CreateMessageFault(); fault = Message.CreateMessage(version, mfault, null); }
/// <summary> /// 启用创建从服务方法过程中的异常返回的自定义 System.ServiceModel.FaultException /// </summary> /// <param name="error">服务操作过程中引发的 Exception 异常。</param> /// <param name="version">消息的 SOAP 版本。</param> /// <param name="fault">双工情况下,返回到客户端或服务的 System.ServiceModel.Channels.Message 对象。</param> public void ProvideFault(Exception error, MessageVersion version, ref Message fault) { string err = string.Format("调用WCF接口 '{0}' 出错", error.TargetSite.Name) + ",详情:\r\n" + error.Message; var newEx = new FaultException(err); MessageFault msgFault = newEx.CreateMessageFault(); fault = Message.CreateMessage(version, msgFault, newEx.Action); LogHelper.Error(err,error); }
public void ProvideFault(Exception ex, MessageVersion version, ref Message msg) { _logger.Error("ServiceExceptionsHandler received unhandled exception", ex); var fe = new FaultException<UnhandledException>(UnhandledException.CreateFromEx(ex)); var mf = fe.CreateMessageFault(); msg = Message.CreateMessage(version, mf, string.Empty); _logger.Error("ServiceExceptionsHandler handled exception and sent ex data to client"); }
public void ProvideFault(Exception error, MessageVersion version, ref Message fault) { if (error is FaultException) return; BusinessServiceException businessFault = new BusinessServiceException(error); FaultException<BusinessServiceException> faultEx = new FaultException<BusinessServiceException>(businessFault, "Error occurs in business service", new FaultCode("BusinessServiceException")); MessageFault msgFault = faultEx.CreateMessageFault(); fault = Message.CreateMessage(version, msgFault, faultEx.Action); }
public void ProvideFault(Exception error, MessageVersion version, ref Message fault) { if (error is FaultException) return; FaultException faultException = new FaultException(error.Message); MessageFault message = faultException.CreateMessageFault(); fault = Message.CreateMessage(version, message, ""); }
/// <summary> /// 自定义消息错误处理 /// </summary> /// <param name="error"></param> /// <param name="version"></param> /// <param name="fault"></param> public void ProvideFault(Exception error, System.ServiceModel.Channels.MessageVersion version, ref System.ServiceModel.Channels.Message fault) { ///全局错误日志记录 //string.Format("ERROR:{0}\r\n引起异常方法:{1}\r\n详细:{2}", // OperationContext.Current.IncomingMessageHeaders.Action.ToString(), // error.TargetSite.Name, error.Message).WriteLog("SystemErrorLog"); var newEx = new FaultException(string.Format("ERROR:{0} ", error.Message)); MessageFault msgFault = newEx.CreateMessageFault(); fault = Message.CreateMessage(version, msgFault, newEx.Action); }
public virtual void ProvideFault(Exception error, MessageVersion version, ref Message fault) { if (fault != null) { return; } var faultException = new FaultException(error.Message); var messageFault = faultException.CreateMessageFault(); fault = Message.CreateMessage(version, messageFault, "Error"); }
public void ProvideFault(Exception error, MessageVersion version, ref Message fault) { if (error.GetType() != typeof (ValidationFaultException)) { string errorCode = Log.Add(error); FaultException faultException = new FaultException<ApplicationFault>(new ApplicationFault(errorCode), "An application error occured with error code: " + errorCode); MessageFault messageFault = faultException.CreateMessageFault(); fault = Message.CreateMessage(version, messageFault, faultException.Action); } }
public void ProvideFault(Exception error, System.ServiceModel.Channels.MessageVersion version, ref System.ServiceModel.Channels.Message fault) { if (error is FaultException) return; // Return a general service error message to the client FaultException faultException = new FaultException("A general service error occured"); MessageFault messageFault = faultException.CreateMessageFault(); fault = Message.CreateMessage(version, messageFault, null); }
/// <summary> /// Enables the creation of a custom <see cref="T:System.ServiceModel.FaultException`1"/> that is returned from an exception in the course of a service method. /// </summary> /// <param name="error">The <see cref="T:System.Exception"/> object thrown in the course of the service operation.</param> /// <param name="version">The SOAP version of the message.</param> /// <param name="fault">The <see cref="T:System.ServiceModel.Channels.Message"/> object that is returned to the client, or service, in the duplex case.</param> public void ProvideFault(Exception error, MessageVersion version, ref Message fault) { if (error == null || error is FaultException) return; //TODO: Log. //Create a fault exception with minimum information and send it var faultException = new FaultException(new FaultReason(error.Message), new FaultCode(error.GetType().AssemblyQualifiedName)); var messageFault = faultException.CreateMessageFault(); fault = Message.CreateMessage(version, messageFault, null); }
public void ProvideFault(Exception ex, MessageVersion version, ref Message msg) { if (msg.IsFault) return; //var genericFaultException = typeof(FaultException<>).MakeGenericType(ex.GetType()); //var customFault = Activator.CreateInstance(genericFaultException, ex) as FaultException; var customFault = new FaultException<ApplicationException>((ApplicationException)ex, "no reason"); var fault = new FaultException("An unexpected exception occured") { Source = ex.ToString() }; var messageFault = customFault.CreateMessageFault(); msg = Message.CreateMessage(version, messageFault, customFault.Action); }
public Message CreateErrorResponse(Exception excp) { FaultException fe = new FaultException(excp.Message); MessageFault fault = fe.CreateMessageFault(); Message response = Message.CreateMessage(MessageVersion.Default, fault, null); HttpResponseMessageProperty http = new HttpResponseMessageProperty(); http.StatusCode = System.Net.HttpStatusCode.OK; http.SuppressEntityBody = true; response.Properties.Add(HttpResponseMessageProperty.Name, http); return response; }
internal static string GetFaultExceptionMessage(FaultException<ExceptionDetail> excobj) { string msg = ""; var faultmess = excobj.CreateMessageFault(); if (faultmess.HasDetail) { ExceptionDetail faultexcdet = faultmess.GetDetail<ExceptionDetail>(); msg = faultexcdet.Message; while (faultexcdet.InnerException != null) { msg = faultexcdet.InnerException.Message; faultexcdet = faultexcdet.InnerException; } } return msg; }
/// <summary> /// 启用创建从服务方法过程中的异常返回的自定义 System.ServiceModel.FaultException<TDetail>。 /// </summary> /// <param name="error">服务操作过程中引发的 System.Exception 对象。</param> /// <param name="version">消息的 SOAP 版本</param> /// <param name="fault">双工情况下,返回到客户端或服务的 System.ServiceModel.Channels.Message 对象。</param> public void ProvideFault(Exception error, MessageVersion version, ref Message fault) { //在异常发生后,异常信息返回前被调用,这里一般不做处理 //将托管异常System.Exception转换为System.ServiceModel.FaultException //FaultException ex = new FaultException("这条消息将返回至调用方"); //MessageFault mf = ex.CreateMessageFault(); //fault = System.ServiceModel.Channels.Message.CreateMessage(version, mf, ex.Action); //WCF服务层统一抛出FaultException类型的异常,对于未处理异常则将其包装成FaultException类型的异常,以免造成信道异常 if (error is FaultException) return; FaultException ex = new FaultException(error.Message); MessageFault mf = ex.CreateMessageFault(); fault = System.ServiceModel.Channels.Message.CreateMessage(version, mf, ex.Action); }