当前位置: 首页>>代码示例>>C#>>正文


C# ServiceModel.FaultException类代码示例

本文整理汇总了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);
         }
      }
开发者ID:MyLobin,项目名称:NLayerAppV2,代码行数:38,代码来源:ApplicationErrorHandler.cs

示例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;
     }
 }
开发者ID:Dadov,项目名称:3rdsemproject,代码行数:28,代码来源:ElectricCar.cs

示例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);
 }
开发者ID:qianlb,项目名称:webcode,代码行数:7,代码来源:ErrorHandlerBehaviorAttribute.cs

示例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;
        }
开发者ID:Praveenmanne,项目名称:Sharepoint-Functions,代码行数:40,代码来源:Program.cs

示例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);
        }
开发者ID:GrgDmr,项目名称:CDAManager,代码行数:32,代码来源:GlobalErrorHandler.cs

示例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);
            }
        }
开发者ID:gabrielsimas,项目名称:MicrosoftNLayerApp,代码行数:32,代码来源:ApplicationErrorHandler.cs

示例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);
		}
开发者ID:nickchal,项目名称:pash,代码行数:7,代码来源:FaultExceptionTest.cs

示例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);
        }
开发者ID:hgouw,项目名称:ResmedCodingExercise,代码行数:32,代码来源:FaultHandler.cs

示例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();
        }
开发者ID:0811112150,项目名称:HappyDayHistory,代码行数:25,代码来源:OrderProcessorService.cs

示例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;
            }
        }
开发者ID:jorgemht,项目名称:Company,代码行数:45,代码来源:ServicioGestion.svc.cs

示例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);
        }
开发者ID:dennyli,项目名称:HandySolution,代码行数:7,代码来源:LighterErrorHandler.cs

示例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;
    }
开发者ID:pillesoft,项目名称:JolTudomE,代码行数:40,代码来源:ExceptionHandler.cs

示例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);
            }
        }
开发者ID:fredp613,项目名称:crmPluginsGnC,代码行数:34,代码来源:PreMultilingualSupportedEntityCreate.cs

示例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);
        }
开发者ID:jonteho,项目名称:ticketing-office,代码行数:14,代码来源:PricingErrorHander.cs

示例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);
        }
开发者ID:kapitanov,项目名称:diploma,代码行数:19,代码来源:ErrorHandler.cs


注:本文中的System.ServiceModel.FaultException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。