本文整理汇总了C#中System.ServiceModel.FaultException.CreateMessageFault方法的典型用法代码示例。如果您正苦于以下问题:C# FaultException.CreateMessageFault方法的具体用法?C# FaultException.CreateMessageFault怎么用?C# FaultException.CreateMessageFault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.ServiceModel.FaultException
的用法示例。
在下文中一共展示了FaultException.CreateMessageFault方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestCreateMessageFault
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");
}
示例2: ProvideFault
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);
}
示例3: ProvideFault
/// <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);
}
}
示例4: ExceptionDetail
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);
}
示例5: ProvideFault
/// <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);
}
}
示例6: ProvideFault
/// <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);
}
示例7: ProvideFault
/// <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);
}
示例8: ProvideFault
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);
}
示例9: ProvideFault
// 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);
}
示例10: ProvideFault
/// <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);
}
示例11: ProvideFault
// 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);
}
示例12: ProvideFault
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);
}
示例13: ProvideFault
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);
}
}
示例14: ProvideFault
/// <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);
}
示例15: ProvideFault
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);
}
}