本文整理汇总了C#中System.ServiceModel.FaultException类的典型用法代码示例。如果您正苦于以下问题:C# FaultException类的具体用法?C# FaultException怎么用?C# FaultException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FaultException类属于System.ServiceModel命名空间,在下文中一共展示了FaultException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
}
示例2: addBooking
public void addBooking(Booking b)
{
MBooking bk = new MBooking();
bk.cId = b.cId;
bk.createDate = DateTime.ParseExact(b.createDate, "dd/MM/yyyy", System.Globalization.CultureInfo.CurrentCulture);
bk.creaditCard = b.payStatus;
bk.tripStart = DateTime.ParseExact(b.tripStart, "dd/MM/yyyy HH:mm", System.Globalization.CultureInfo.CurrentCulture);
bk.totalPrice = b.totalPrice;
List<MBookingLine> bkls = new List<MBookingLine>();
List<BookingLine> bls = b.bookinglines.ToList<BookingLine>();
for (int i = 0; i < bls.Count; i++)
{
MBookingLine bl = new MBookingLine();
bl.price = bls[i].price;
bl.quantity = bls[i].quantity;
bl.Station.Id = bls[i].station.Id;
bl.time = bls[i].time;
bl.BatteryType.id = bls[i].BatteryType.ID;
bkls.Add(bl);
}
bk.bookinglines = bkls;
BookingCtr bCtr = new BookingCtr();
if (!bCtr.addBooking(bk))
{
FaultException f = new FaultException("Booking failed because one of the station is fully booked");
throw f;
}
}
示例3: 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);
}
示例4: ConvertToDictionary
/// <summary>
/// Converts to dictionary.
/// </summary>
/// <param name="metaData">The meta data.</param>
/// <param name="customError">Parameter for returning the exception.</param>
/// <returns>dictionary</returns>
internal Dictionary<string, string> ConvertToDictionary(string metaData, out FaultException customError)
{
customError = null;
if (!string.IsNullOrEmpty(metaData))
{
var returnHashTable = new Dictionary<string, string>();
try
{
// spliting using the seperators
var metaDataSeparators = new string[] { "~|#" };
var split = metaData.Split(metaDataSeparators, StringSplitOptions.None);
foreach (string t in split)
{
var valueSeparators = new string[] { "~|~" };
var value = t.Split(valueSeparators, StringSplitOptions.None);
returnHashTable.Add(value[0].Trim(), value[1].Trim());
}
}
catch (Exception e)
{
Trace.TraceError(DateTime.Now + ": " + e.Message.ToString() + Environment.NewLine + e.StackTrace);
customError = new FaultException(e.Message);
}
return returnHashTable;
}
else
{
//customError = new FaultException(string.Format(Properties.Resources.NOT_VALID_STRING, "MetaData"));
}
return null;
}
示例5: ProvideFault
public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
{
FaultException faultException;
var logger = LogManager.GetCurrentClassLogger();
if (error != null && error is ObjectValidationException)
{
faultException = new FaultException<ValidationFault>(new ValidationFault(((ObjectValidationException)error).ValidationErrors.Select(item =>
new ValidationError
{
ErrorMessage = item.ErrorMessage,
ObjectName = item.ObjectName,
PropertyName = item.PropertyName
})), new FaultReason("Validation error"));
logger.Error(error, "Validation error in GlobalError filter");
}
else
{
faultException = new FaultException<InternalServiceFault>(new InternalServiceFault(error,
string.Format("Exception caught at GlobalErrorHandler{0}Method: {1}{2}Message:{3}",
Environment.NewLine, error.TargetSite.Name, Environment.NewLine, error.Message)));
logger.Error(error, "Generic internal error in GlobalError filter");
}
// Shield the unknown exception
//FaultException faultException = new FaultException<SimpleErrorFault>(new SimpleErrorFault(), new FaultReason("Server error encountered. All details have been logged."));
//new FaultException("Server error encountered. All details have been logged.");
MessageFault messageFault = faultException.CreateMessageFault();
fault = Message.CreateMessage(version, messageFault, faultException.Action);
}
示例6: 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);
}
}
示例7: TestCode
public void TestCode ()
{
// default Code is a SenderFault with a null SubCode
FaultException<int> e = new FaultException<int> (0);
Assert.IsTrue (e.Code.IsSenderFault);
Assert.IsNull (e.Code.SubCode);
}
示例8: Handle
public static void Handle(FaultException faultException)
{
Exception innerException = null;
if (faultException is FaultException<RecordNotFoundFault>)
{
var recordNotFoundFault = faultException as FaultException<RecordNotFoundFault>;
innerException = new RecordNotFoundException(recordNotFoundFault.Message);
}
if (faultException is FaultException<InvalidRecordFault>)
{
var invalidRecordFault = faultException as FaultException<InvalidRecordFault>;
innerException = new InvalidRecordException(invalidRecordFault.Message);
}
if (faultException is FaultException<DuplicateRecordFoundFault>)
{
var duplicateRecordFault = faultException as FaultException<DuplicateRecordFoundFault>;
innerException = new DuplicateRecordFoundException(duplicateRecordFault.Message);
}
if (innerException == null)
{
throw faultException;
}
if (innerException == null)
{
throw faultException;
}
throw new StockException("A exception has occured.",innerException);
}
示例9: Submit
public void Submit(Order order)
{
Console.WriteLine("Begin to process the order of the order No.: {0}", order.OrderNo);
FaultException exception = null;
if (order.OrderDate < DateTime.Now) {
exception = new FaultException(new FaultReason("The order has expried"), new FaultCode("sender"));
Console.WriteLine("It's fail to process the order.\n\tOrder No.: {0}\n\tReason:{1}", order.OrderNo, "The order has expried");
} else {
Console.WriteLine("It's successful to process the order.\n\tOrder No.: {0}", order.OrderNo);
}
NetMsmqBinding binding = new NetMsmqBinding();
binding.ExactlyOnce = false;
binding.Security.Transport.MsmqAuthenticationMode = MsmqAuthenticationMode.None;
binding.Security.Transport.MsmqProtectionLevel = ProtectionLevel.None;
ChannelFactory<IOrderRessponse> channelFactory = new ChannelFactory<IOrderRessponse>(binding);
OrderResponseContext responseContext = OrderResponseContext.Current;
IOrderRessponse channel = channelFactory.CreateChannel(new EndpointAddress(responseContext.ResponseAddress));
using (OperationContextScope contextScope = new OperationContextScope(channel as IContextChannel)) {
channel.SubmitOrderResponse(order.OrderNo, exception);
}
Console.Read();
}
示例10: addAccionComercial
/********************************************************************/
/*****************************FIN IVAN*******************************/
/********************************************************************/
/********************************************************************/
/*****************************MIGUEL*********************************/
/********************************************************************/
/// <summary>
/// Método que añade una accion comercial a la base de datos
/// </summary>
/// <param name="accion"> Objeto usuario a añadir en la base de datos</param>
/// <returns>Devuelve true si se ha añadido el registro correctamente. False si no.</returns>
public int addAccionComercial(AccionComercialData accion)
{
if (accion == null) return -1;
try
{
using (GestionEmpresasEntities db = new GestionEmpresasEntities())
{
AccionComercial nuevo = new AccionComercial();
nuevo.descripcion = accion.descripcion;
nuevo.comentarios = accion.comentarios;
nuevo.fechaHora = accion.fechaHora;
nuevo.idUsuario = accion.idUsuario;
nuevo.idTipoAccion = accion.idTipoAccion;
nuevo.idEstadoAccion = accion.idEstadoAccion;
nuevo.idEmpresa = accion.idEmpresa;
db.AccionComercial.Add(nuevo);
db.SaveChanges();
return nuevo.idAccion;
}
}
catch (SqlException ex)
{
FaultException fault = new FaultException("ERROR SQL: " + ex.Message,
new FaultCode("SQL"));
throw fault;
}
catch (Exception ex)
{
FaultException fault = new FaultException("ERROR: " + ex.Message,
new FaultCode("GENERAL"));
throw fault;
}
}
示例11: 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);
}
示例12: GetUserFriendlyErrorMessage
/// <summary>
/// calculates the collection of the error codes recevied from SQL stored procedure
/// </summary>
/// <param name="excobj"></param>
/// <returns>new line separated error messages</returns>
internal static string GetUserFriendlyErrorMessage(FaultException<ExceptionDetail> excobj) {
string msg = string.Empty;
string faultmsg = GetFaultExceptionMessage(excobj);
string spname = faultmsg.Split('.')[0];
int code = int.Parse(faultmsg.Split(':')[1]);
List<int> codes = new List<int>();
int quotbase = 1000;
while (true) {
if (code >= quotbase) {
int modulo = code % quotbase;
if (modulo == 0) {
codes.Add(quotbase);
break;
}
else if (modulo >= 1) {
codes.Add(quotbase);
code = code - quotbase;
quotbase = quotbase / 10;
}
}
else
quotbase = quotbase / 10;
}
StringBuilder sb = new StringBuilder();
foreach (int err in codes) {
sb.AppendLine(string.Format("{0} - {1}", err, _SPErrorCodes.Find(e => e.ErrorCode == err && e.SPName == spname).ErrorMessage));
}
msg = sb.ToString();
return msg;
}
示例13: Execute
public void Execute(IServiceProvider serviceProvider)
{
//Extract the tracing service for use in debugging sandboxed plug-ins.
ITracingService tracingService =
(ITracingService)serviceProvider.GetService(typeof(ITracingService));
FaultException ex1 = new FaultException();
// Obtain the execution context from the service provider.
IPluginExecutionContext context = (IPluginExecutionContext)
serviceProvider.GetService(typeof(IPluginExecutionContext));
try
{
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
Entity target = (Entity)context.OutputParameters["BusinessEntity"];
if (new UserLocaleHelper(service, context).getUserLanguage() == 1033) {
if (target.Attributes.Contains("address1_line1"))
{
target["name"] = target.GetAttributeValue<string>("address1_line1");
}
else
{
target["name"] = "testing";
}
} else {
target["name"] = "French";
}
}
catch (FaultException<OrganizationServiceFault> ex)
{
throw new InvalidPluginExecutionException("An error occurred in the multi lingual plug-in.", ex);
}
}
示例14: 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);
}
示例15: 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);
}