Ejemplo n.º 1
0
        Type Try_get_reqType(string providerName, ServiceConfiguration serviceConfiguration)
        {
            try
            {
                Type reqType = ReflectionFunctions.CreateType(serviceConfiguration.Request);

                return(reqType);
            }
            catch (Exception ex)
            {
                throw get_TechnicalException_error_loading_req(serviceConfiguration, ex);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Ejecuta un servicio de negocio.
        /// </summary>
        /// <param name="providerName">Nombre del proveedor de metadata de servicios.-</param>
        /// <param name="serviceName">Nombre del servicio de negocio.</param>
        /// <param name="jsonRequest">JSON con datos de entrada para la  ejecución del servicio.</param>
        /// <param name="hostContext">Info del despachador de servicio</param>
        /// <returns>JSON con el resultado de la  ejecución del servicio.</returns>
        /// <date>2008-04-07T00:00:00</date>
        /// <author>moviedo</author>
        public static string ExecuteServiceJson(string providerName, string serviceName, string jsonRequest, HostContext hostContext)
        {
            string wResult;

            ServiceConfiguration wServiceConfiguration = FacadeHelper.GetServiceConfiguration(providerName, serviceName);

            Type reqType = ReflectionFunctions.CreateType(wServiceConfiguration.Request);

            if (reqType == null)
            {
                TechnicalException te = new TechnicalException(string.Concat("El despachador de servicio no pudo continuar debido\r\na que no logro construir el requets del servicio: ",
                                                                             serviceName, "\r\nVerifique que se encuentre los componentes necesarios para su ejecucion esten en el servidor de aplicación. "));

                Fwk.Exceptions.ExceptionHelper.SetTechnicalException <StaticFacade>(te);

                if (string.IsNullOrEmpty(ConfigurationsHelper.HostApplicationName))
                {
                    te.Source = "Despachador de servicios en " + Environment.MachineName;
                }
                else
                {
                    te.Source = ConfigurationsHelper.HostApplicationName;
                }

                te.ErrorId = "7003";
                throw te;
            }
            var wRequest = (IServiceContract)Fwk.HelperFunctions.SerializationFunctions.DeSerializeObjectFromJson(reqType, jsonRequest);

            wRequest.ContextInformation.HostName = hostContext.HostName;
            wRequest.ContextInformation.HostIp   = hostContext.HostIp;
            IServiceContract res     = ExecuteService(providerName, (IServiceContract)wRequest);
            Type             resType = Type.GetType(wServiceConfiguration.Response);

            wResult = Fwk.HelperFunctions.SerializationFunctions.SerializeObjectToJson(resType, res);
            return(wResult);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Ejecuta el servicio de negocio.
        /// </summary>
        /// <param name="pRequest">Request de entrada que se pasa al servicio</param>
        /// <param name="pServiceConfiguration">configuración del servicio.</param>
        /// <param name="pserviError">serviError</param>
        /// <returns>XML que representa el resultado de la  ejecución del servicio.</returns>
        /// <date>2007-08-07T00:00:00</date>
        /// <author>moviedo</author>
        static IServiceContract RunService(IServiceContract pRequest, ServiceConfiguration pServiceConfiguration, out ServiceError pserviError)
        {
            IServiceContract wResponse = null;

            try
            {
                pRequest.InitializeServerContextInformation();
                // obtención del Response.
                Type wServiceType = ReflectionFunctions.CreateType(pServiceConfiguration.Handler);

                object wServiceInstance = Activator.CreateInstance(wServiceType);
                wResponse =
                    (wServiceType.GetMethod("Execute").Invoke(wServiceInstance, new object[] { pRequest }) as
                     IServiceContract);

                wResponse.InitializeServerContextInformation();
            }

            #region [manage Exception]
            catch (FunctionalException fx)
            {
                fx.ServiceName = wResponse.ServiceName;
                //El response existe por q de otra manera no existiria una FunctionalException
                wResponse.Error = GetServiceError(fx);
            }
            catch (System.IO.FileNotFoundException ex)
            {
                wResponse = GetResponse(pServiceConfiguration);// (IServiceContract)ReflectionFunctions.CreateInstance(pServiceConfiguration.Response);

                wResponse.Error = new ServiceError();
                System.Text.StringBuilder wMessage = new StringBuilder();

                wResponse.Error.ErrorId = "7003";

                #region Message
                wMessage.Append("El despachador de servicio no pudo encontrar alguna de los siguientes assemblies \r\n");

                wMessage.Append("o alguna de sus dependencias: \r\n");

                wMessage.Append("Servicio: ");
                wMessage.Append(pServiceConfiguration.Handler);
                wMessage.Append(Environment.NewLine);

                wMessage.Append("Request: ");
                wMessage.Append(pServiceConfiguration.Request);
                wMessage.Append(Environment.NewLine);

                wMessage.Append("Response: ");
                wMessage.Append(pServiceConfiguration.Response);
                wMessage.Append(Environment.NewLine);

                wMessage.Append("Mensaje original :");
                wMessage.Append(Environment.NewLine);
                wMessage.Append(ex.Message);
                #endregion

                wResponse.Error.Message = wMessage.ToString();
                FillServiceError(wResponse.Error, ex);
            }
            catch (System.Reflection.TargetInvocationException ex)
            {
                wResponse       = GetResponse(pServiceConfiguration);
                wResponse.Error = GetServiceError(ex.InnerException);
            }
            catch (TypeLoadException tl)
            {
                wResponse = GetResponse(pServiceConfiguration);
                System.Text.StringBuilder wMessage = new StringBuilder();
                wResponse.Error = new ServiceError();

                wResponse.Error.ErrorId = "7002";
                wMessage.Append("No se encuentra el o los assemblies para cargar el servicio " + pServiceConfiguration.Name);
                wMessage.AppendLine();
                wMessage.AppendLine(tl.Message);
                wResponse.Error.Message = wMessage.ToString();
                FillServiceError(wResponse.Error, tl);
            }
            catch (Exception ex)
            {
                wResponse       = GetResponse(pServiceConfiguration);// (IServiceContract)ReflectionFunctions.CreateInstance(pServiceConfiguration.Response);
                wResponse.Error = GetServiceError(ex);
            }

            #endregion

            pserviError = wResponse.Error;

            #region < Log >
            //Audito ensegundo plano
            Action actionAudit = () => { DoAudit(pServiceConfiguration, pRequest, wResponse); };
            Task.Factory.StartNew(actionAudit);


            #endregion



            return(wResponse);
        }