public AutoRepairShopInfoList GetAllAutoRepairRequest(AutoRepairShopRequest autoRepairShopRequest) { List<AutoRepairDTO> autoRepairDTOList = new List<AutoRepairDTO>(); AutoRepairShopInfoList autoRepairShopInfoList = new AutoRepairShopInfoList(); try { using (AutoRepairShopRepositoryBLL context = new AutoRepairShopRepositoryBLL()) { autoRepairDTOList = context.GetAllAutoRepairs(); TranslateAutoRepairShopDTOListToAutoRepairShopInfoSList(autoRepairDTOList, ref autoRepairShopInfoList); } } catch (Exception ex) { //Part 18 Throwing fault exceptions from a WCF service throw new FaultException<AutoRepairFault>( new AutoRepairFault { ErrorMessage = ex.Message, Source = ex.Source, StackTrace = ex.StackTrace, Target = ex.TargetSite.ToString() }, new FaultReason(string.Format(CultureInfo.InvariantCulture, "{0}", "Service fault exception: " + ex.Message))); } if (autoRepairShopInfoList == null) { string msg = string.Format("No Auto Repair Shop found."); throw new FaultException<AutoRepairFault>(new AutoRepairFault { ErrorMessage = msg, Source = null, StackTrace = null, Target = null }, new FaultReason(string.Format(CultureInfo.InvariantCulture, "{0}", "Service fault exception: " + msg))); } return autoRepairShopInfoList; }
/* // Controlling WCF message protection using ProtectionLevel parameter // www.youtube.com/watch?v=ybY9dD24gtI&index=48&list=PL6n9fhu94yhVxEyaRMaMN_-qnDdNVGsL1 [OperationContract(Name = "GetAllAutoRepairs", ProtectionLevel=ProtectionLevel.None)] */ // User has to be in Role to call the service operation // [PrincipalPermission(SecurityAction.Demand, Role = "member")] public List<AutoRepairWCF> GetAllAutoRepairs() { List<AutoRepairDTO> autoRepairDTOList = new List<AutoRepairDTO>(); // List<AutoRepairWCF> autoRepairWCFList = new List<AutoRepairWCF>(); List<AutoRepairWCF> autoRepairWCFList2 = new List<AutoRepairWCF>(); try { using(AutoRepairShopRepositoryBLL context = new AutoRepairShopRepositoryBLL()) { autoRepairDTOList = context.GetAllAutoRepairs(); // TranslateAutoRepairShopDTOListToAuotoRepairWCFList(autoRepairDTOList, ref autoRepairWCFList); autoRepairWCFList2 = TranslateAutoRepairShopDTOListToAuotoRepairWCFList2(autoRepairDTOList); } } catch (Exception ex) { if (ex.InnerException != null) ex = ex.InnerException; string sqlExceptionMessage = null; if (ex is SqlException) { sqlExceptionMessage = "The underlying provider failed on Open. Cannot Open the Database."; throw new FaultException<AutoRepairFault>( new AutoRepairFault { ErrorMessage = sqlExceptionMessage, Source = ex.Source, StackTrace = ex.StackTrace, Target = ex.TargetSite.ToString() }, new FaultReason(string.Format(CultureInfo.InvariantCulture, "{0}", "Service fault exception: " + ex.Message))); } else { throw new FaultException<AutoRepairFault>( new AutoRepairFault { ErrorMessage = sqlExceptionMessage + "\n" + ex.Message, Source = ex.Source, StackTrace = ex.StackTrace, Target = ex.TargetSite.ToString() }, new FaultReason(string.Format(CultureInfo.InvariantCulture, "{0}", "Service fault exception: " + ex.Message))); } } if (autoRepairDTOList == null) { string msg = string.Format("No Auto Repair Shop found."); throw new FaultException<AutoRepairFault>(new AutoRepairFault { ErrorMessage = msg, Source = null, StackTrace = null, Target = null }, new FaultReason(string.Format(CultureInfo.InvariantCulture, "{0}", "Service fault exception: " + msg))); } return autoRepairWCFList2; //return autoRepairWCFList; }