• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# ServiceModel.FaultException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.ServiceModel.FaultException的典型用法代码示例。如果您正苦于以下问题:C# FaultException类的具体用法?C# FaultException怎么用?C# FaultException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



FaultException类属于System.ServiceModel命名空间,在下文中一共展示了FaultException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


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


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


示例18: When_Passed_A_Non_Typed_Fault_Exception_ToException_Returns_A_Generic_Exception

        public void When_Passed_A_Non_Typed_Fault_Exception_ToException_Returns_A_Generic_Exception()
        {
            var faultException = new FaultException("Test fault exception");
            var translator = new ExceptionTranslator();

            var result = translator.ToException(faultException);

            Assert.That(result, Is.TypeOf(typeof(System.Exception)));
        }
开发者ID:ninjaferret,项目名称:NinjaFerret.Wcf,代码行数:9,代码来源:TestExceptionTranslator.cs


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


示例20: When_Passed_A_Translatable_Fault_ToException_Returns_A_Generic_Exception

        public void When_Passed_A_Translatable_Fault_ToException_Returns_A_Generic_Exception()
        {
            var faultException = new FaultException<TestFault>(new TestFault(), "Test fault exception");
            var translator = new ExceptionTranslator();

            var result = translator.ToException(faultException);

            Assert.That(result, Is.TypeOf(typeof(TestException)));
        }
开发者ID:ninjaferret,项目名称:NinjaFerret.Wcf,代码行数:9,代码来源:TestExceptionTranslator.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# ServiceModel.FaultReason类代码示例发布时间:2022-05-26
下一篇:
C# ServiceModel.FaultCode类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap