Ejemplo n.º 1
0
        public static O ExecuteService <S, O>(ConfiguracionSistemaURLsEnumDestino destino, Func <S, O> methodName)
        {
            ChannelFactory <S> client = WCFHelper.CreateChannelFactory <S>(destino);

            client.Open();
            S service = client.CreateChannel();

            using (new OperationContextScope((IContextChannel)service))
            {
                try
                {
                    return(methodName(service));
                }
                catch (CommunicationException ce)
                {
                    throw new M4TraderApplicationException("Error de comunicación", ce);
                }
                finally
                {
                    try
                    {
                        ((IClientChannel)service).Close();
                    }
                    catch (CommunicationException)
                    {
                        // Ignore various exceptions regarding the Channel's current state
                    }
                    catch (TimeoutException)
                    {
                        // Ignore Timeouts
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static string GetServiceUrl(ConfiguracionSistemaURLsEnumDestino destino)
        {
            switch (destino)
            {
            case ConfiguracionSistemaURLsEnumDestino.Mobile:
                return(OrdenesApplication.Instance.ContextoAplicacion.Urls.Find(x => x.TipoUrl == ConfiguracionSistemaURLsEnumDestino.Mobile).Url);

            case ConfiguracionSistemaURLsEnumDestino.Swift:
                return(OrdenesApplication.Instance.ContextoAplicacion.Urls.Find(x => x.TipoUrl == ConfiguracionSistemaURLsEnumDestino.Swift).Url);

            case ConfiguracionSistemaURLsEnumDestino.OrdenesFIX:
                return(OrdenesApplication.Instance.ContextoAplicacion.Urls.Find(x => x.TipoUrl == ConfiguracionSistemaURLsEnumDestino.OrdenesFIX).Url);

            case ConfiguracionSistemaURLsEnumDestino.OrdenesFIXTcp:
                return(OrdenesApplication.Instance.ContextoAplicacion.Urls.Find(x => x.TipoUrl == ConfiguracionSistemaURLsEnumDestino.OrdenesFIXTcp).Url);

            case ConfiguracionSistemaURLsEnumDestino.DoubleAuthentication:
                return(OrdenesApplication.Instance.ContextoAplicacion.Urls.Find(x => x.TipoUrl == ConfiguracionSistemaURLsEnumDestino.DoubleAuthentication).Url);

            case ConfiguracionSistemaURLsEnumDestino.NotificacionesDMAFIX:
                return(OrdenesApplication.Instance.ContextoAplicacion.Urls.Find(x => x.TipoUrl == ConfiguracionSistemaURLsEnumDestino.NotificacionesDMAFIX).Url);

            case ConfiguracionSistemaURLsEnumDestino.ChatService:
                return(OrdenesApplication.Instance.ContextoAplicacion.Urls.Find(x => x.TipoUrl == ConfiguracionSistemaURLsEnumDestino.ChatService).Url);

            default:
                return("no valido");
            }
        }
Ejemplo n.º 3
0
        public static void ExecuteService <S>(ConfiguracionSistemaURLsEnumDestino destino, Action <S> methodName)
        {
            ChannelFactory <S> client = WCFHelper.CreateChannelFactory <S>(destino);

            client.Open();
            S service = client.CreateChannel();

            using (OperationContextScope ocs = new OperationContextScope((IContextChannel)service))
            {
                try
                {
                    methodName(service);
                }

                finally
                {
                    try
                    {
                        ((IClientChannel)service).Close();
                    }
                    catch (CommunicationException ce)
                    {
                        throw new MAECommunicationException("Error de comunicación", ce);
                    }
                    catch (TimeoutException)
                    {
                        // Ignore Timeouts
                    }
                }
            }
        }
Ejemplo n.º 4
0
        private static ChannelFactory <T> CreateChannelFactory <T>(ConfiguracionSistemaURLsEnumDestino destino)
        {
            string             uri             = WCFHelper.GetServiceUrl(destino);
            EndpointAddress    endpointAddress = new EndpointAddress(uri);
            ChannelFactory <T> channelFactory;

            if (uri.StartsWith("net.pipe", StringComparison.OrdinalIgnoreCase))
            {
                NetNamedPipeBinding binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None);
                channelFactory = new ChannelFactory <T>();
                channelFactory.Endpoint.Binding = binding;
                channelFactory.Endpoint.Address = endpointAddress;
            }
            else if (uri.StartsWith("net.tcp", StringComparison.OrdinalIgnoreCase))
            {
                NetTcpBinding binding = new NetTcpBinding
                {
                    MaxReceivedMessageSize = TwoGigaBytes,
                    MaxBufferPoolSize      = TwoGigaBytes,
                    MaxBufferSize          = TwoGigaBytes,
                };
                binding.Security.Mode           = SecurityMode.None;
                channelFactory                  = new ChannelFactory <T>();
                channelFactory.Endpoint.Binding = binding;
                channelFactory.Endpoint.Address = endpointAddress;
            }
            else
            {
                WebHttpBinding webHttpBinding = WCFHelper.CreateWebHttpBinding(uri);
                channelFactory = new ChannelFactory <T>();
                channelFactory.Endpoint.Behaviors.Add(new WebHttpBehavior());
                channelFactory.Endpoint.Binding = webHttpBinding;
                channelFactory.Endpoint.Address = endpointAddress;
            }
            return(channelFactory);
        }