PASO 1 - Creación proyecto de entidades de datos - Creación de proyecto tipo biblioteca de clases - Agregar Referencia system.Runtime.Serialization - Agregamos using clase de system.Runtime.Serialization - Referencias la clase como [DataContract] - Agregar los miembros de la clase [DataMember] (objetos de tabla) - Creación proyecto de acceso a datos - Creación de proyecto tipo biblioteca de clases - Agregamos la referencia de la clase entidades - Agregar Referencia System.Linq - Agregamos Carpeta contenedora de clases contexto - Agregamos clases de contextoLinq .dbml - Conectamos con la base de datos mediante el explorador de servidores - Seleccionamos los objetos(Tablas y procedimientos) que vamos a incluir en las diferentes clases dbml - Creamos la clase Helper para mandar la conexion de la base de datos - Agregamos al proyecto la referencia System.Configuration - La clase helper lleva la siguiente estructura public static class Helper { public static string ConnectionString() { return ConfigurationManager.ConnectionStrings["SIHCEI_SBXConnectionString"].ConnectionString; } } - Agregamos la clase para acceso a datos - Agregamos Using DataAccess.Context - Agregamos Using Entities - El codigo para clase Data Access es de la siguiente manera Para lectura public class RegistroDataAcess { public List Get_registro(Registro mdlRegistro) { List mdlReturn = new List(); try { using (lnqRegistroDataContext dc = new lnqRegistroDataContext(Helper.ConnectionString())) { var query = from item in dc.stp_get_DataRegistros(mdlRegistro.intRegistroId) select new Registro() { intRegistroId = item.INTREGISTROID, intNumParticipantes = (int)item.INTNUMPARTICIPANTES, bitActivo = (bool)item.BITACTIVO, datFechaAlta = item.DATFECHAALTA.ToString(), datFechaInicioReg = item.DATFECHAFINREG.ToString(), intUsuarioIdAlta = (int)item.INTUSUARIOIDALTA }; mdlReturn.AddRange(query); } } catch (Exception exx) { throw exx; } return mdlReturn; } } - El codigo para clase Data Access es de la siguiente manera Para Actualizacion e inserccion public ServiceResult ActualizaCreditoHipotecario(CreditoHipotecario creditoHipotecario) { ServiceResult resultado = new ServiceResult(); try { using (lnqCreditoHipotecarioDataContext dc = new lnqCreditoHipotecarioDataContext(Helper.ConnectionString())) { resultado.ResultValue = dc.sp_uCreditoHipotecario(creditoHipotecario.iOpcion, creditoHipotecario.iOperacionId, creditoHipotecario.iPersonaId, (short?)creditoHipotecario.sintDestinoCredID, (short?)creditoHipotecario.sintTasaRefID, (byte?)creditoHipotecario.tintTipoAltaID, (byte?)creditoHipotecario.tintTipoBajaID, (short?)creditoHipotecario.sintTipoCreditoID/*, creditoHipotecario.dpConcedido*/, creditoHipotecario.dMProyecto, (short?)creditoHipotecario.sintEntAsegID, (short?)creditoHipotecario.sintEntidadCofinanID,(byte?) creditoHipotecario.tintTipoSeguroID, creditoHipotecario.bitSeguroCargoCli,(byte?) creditoHipotecario.tintTipoTasaIntID, creditoHipotecario.GastosOriginacion, creditoHipotecario.TasaComisiones, creditoHipotecario.TasaInteres,(byte?) creditoHipotecario.tintSectorLabID, creditoHipotecario.iComprobanteEmpleoId, creditoHipotecario.sCodigoPostal, creditoHipotecario.iEstadoId, creditoHipotecario.iDelegMpoId, creditoHipotecario.decImporteIngreso,creditoHipotecario.BitConvenio); } } catch (Exception ex) { resultado.ServiceOk = false; throw ex; } return resultado; } - Creación proyecto Logica del negocio - Creación de proyecto tipo biblioteca de clases - Agregamos la referencia system.Configuration - Agregamos la referencia System.Transaction - Agregamos la referencia de la clase entidades - Agregamos la referencia de la clase de acceso a datos - Agregamos la clase para la programación logica - Agregamos using using BusinessEntities; using DataAccess; - Codigo ejemplo consulta class RegistroLogic { private RegistroDataAcess RegistroDA; public RegistroLogic() { RegistroDA = new RegistroDataAcess(); } public List get_DataRegistro(Registro mdlRegistro) { List mdlReturn = new List(); try { mdlReturn = RegistroDA.Get_registro(mdlRegistro); } catch(Exception ex) { throw ex; } return mdlReturn; } } - Inserccion public int InsertarEditar(Garantia garantia) { int resultado = 0; try { resultado= GarantiasDA.InsertarEditar(garantia); } catch (Exception ex) { throw ex; } return resultado; } - Creación proyecto Logica del negocio - Creación de proyecto tipo biblioteca de clases - Agregamos la referencia system.RuntimeSerialization - Agregamos la referencia system.ServiceModel - Agregamos la referencia system.Transaction - Agregamos la referencia system.Web.Services - Agregamos la referencia de la clase entidades - Agregamos la referencia de la business logic - Agregamos la clase EvntLogManager public class EventLogManager { private static string AppName = "HCM"; public static void LogInfoEntry(string InfoMessage) { EventLog elog = new EventLog(); if (!EventLog.SourceExists(AppName)) { EventLog.CreateEventSource(AppName, AppName); } elog.Source = AppName; elog.EnableRaisingEvents = true; elog.WriteEntry(InfoMessage, EventLogEntryType.Information); } public static void LogErrorEntry(string ErrorMessage) { EventLog elog = new EventLog(); if (!EventLog.SourceExists(AppName)) { EventLog.CreateEventSource(AppName, AppName); } elog.Source = AppName; elog.EnableRaisingEvents = true; elog.WriteEntry(ErrorMessage, EventLogEntryType.Error); } } - Agregamos carpeta contenedora de los servicios - Agregamos proyecto de tipo biblioteca de servicios WCF - Agregamos carpeta contenedora de los contratos - Agregamos objeto interface del servicio - Agregamos using System.ServiceModel; - Agregamos using Registec.Entities; - Definimos la clase como [ServiceContract] - Definimos los eventos como [OperationContract] - Interface de ejemplo [ServiceContract] interface IinterfacesServiceGarantia { [OperationContract] ServiceResult InsertaActualizaGarantia(Garantia garantia); [OperationContract] List ObtieneGarantias(int? iOperacionId, int individual); } - Agregamos las clases de interface de los servicios que implemente los metodos declarados en la interface - Agregamos using de entities y de busines logic - cambiamos el name space de la interface y de la clase para que sea la misma (namespace Registec.Services) y poder heredar de ella - Agregamos los metodos declarados en la interface public partial class InterfaceServiceRegistro : IinterfaceServiceRegistro { List get_DataRegistro(Registro mdlRegistro) { List mdlReturn = new List(); try { mdlReturn = (new RegistroLogic()).get_DataRegistro(mdlRegistro); } catch(Exception ex) { #if (DEBUG) Console.WriteLine("Error en InterfacesServiceGarantias. ListadoGarantias: " + ex.Message); #else EventLogManager.LogErrorEntry("Error en CatalogosService.ListarInterfaces: " + ex.Message); //TODO: Codificar envío de notificación de error al EventLog #endif } return mdlReturn; } }