Ejemplo n.º 1
0
        public ListenerServiceHost(int overridePortNumber, bool requireSecureConnection, bool useCrossDomainService, bool useServiceConfiguration)
        {
            int listenerPort = overridePortNumber == 0 ? DataphorServiceUtility.DefaultListenerPortNumber : overridePortNumber;

            _listenerHost = useServiceConfiguration ? new CustomServiceHost(typeof(ListenerService)) : new ServiceHost(typeof(ListenerService));

            if (!useServiceConfiguration)
            {
                _listenerHost.AddServiceEndpoint
                (
                    typeof(IListenerService),
                    DataphorServiceUtility.GetBinding(),
                    DataphorServiceUtility.BuildListenerURI(Environment.MachineName, listenerPort)
                );
            }

            try
            {
                _listenerHost.Open();
            }
            catch
            {
                // An error indicates the service could not be started because there is already a listener running in another process.
            }
        }
Ejemplo n.º 2
0
        protected override void OnStart(string[] args)
        {
            var service = new InstancerService();

            service.BinDirectory      = ServiceSettings.Default.BinDirectory;
            service.InstanceDirectory = ServiceSettings.Default.InstanceDirectory;
            _host = new ServiceHost(service);
            _host.AddServiceEndpoint
            (
                typeof(IInstancerService),
                DataphorServiceUtility.GetBinding(),
                DataphorServiceUtility.BuildInstanceURI(Environment.MachineName, Constants.InstancerPortNumber, Constants.InstancerName)
            );

            _host.Open();
        }
Ejemplo n.º 3
0
        public void Open()
        {
            if (!IsActive)
            {
                if (!String.IsNullOrEmpty(_clientConfigurationName))
                {
                    _channelFactory = new ChannelFactory <IClientDataphorService>(_clientConfigurationName);
                }
                else
                {
                    if (_overridePortNumber == 0)
                    {
                        Uri uri = new Uri(ListenerFactory.GetInstanceURI(_hostName, _overrideListenerPortNumber, _instanceName));
                        _channelFactory =
                            new ChannelFactory <IClientDataphorService>
                            (
                                DataphorServiceUtility.GetBinding(),
                                new EndpointAddress(uri, DataphorServiceUtility.BuildEndpointIdentityCall())
                            );
                    }
                    else
                    {
                        _channelFactory =
                            new ChannelFactory <IClientDataphorService>
                            (
                                DataphorServiceUtility.GetBinding(),
                                new EndpointAddress
                                (
                                    new Uri(DataphorServiceUtility.BuildInstanceURI(_hostName, _overridePortNumber, _instanceName)),
                                    DataphorServiceUtility.BuildEndpointIdentityCall()
                                )
                            );
                    }
                }

                DataphorServiceUtility.ServiceEndpointHook(_channelFactory.Endpoint);
            }
        }
Ejemplo n.º 4
0
        public void Start()
        {
            if (!IsActive)
            {
                try
                {
                    InstanceManager.Load();

                    ServerConfiguration instance = InstanceManager.Instances[_instanceName];
                    if (instance == null)
                    {
                        // Establish a default configuration
                        instance = ServerConfiguration.DefaultInstance(_instanceName);
                        InstanceManager.Instances.Add(instance);
                        InstanceManager.Save();
                    }

                    _server = new Server();
                    instance.ApplyTo(_server);
                    _remoteServer = new RemoteServer(_server);
                    _nativeServer = new NativeServer(_server);
                    _server.Start();
                    try
                    {
                        _server.LogMessage("Creating WCF Service...");
                        _service = new DataphorService(_remoteServer);

                        _server.LogMessage("Creating Native CLI Service...");
                        _nativeService = new NativeCLIService(_nativeServer);

                        _server.LogMessage("Configuring Service Host...");
                        _serviceHost = instance.UseServiceConfiguration ? new CustomServiceHost(_service) : new ServiceHost(_service);

                        if (!instance.UseServiceConfiguration)
                        {
                            _serviceHost.AddServiceEndpoint
                            (
                                typeof(IDataphorService),
                                DataphorServiceUtility.GetBinding(),
                                DataphorServiceUtility.BuildInstanceURI(Environment.MachineName, instance.PortNumber, instance.Name)
                            );
                        }

                        _server.LogMessage("Opening Service Host...");
                        _serviceHost.Open();

                        _server.LogMessage("Configuring Native CLI Service Host...");
                        _nativeServiceHost = instance.UseServiceConfiguration ? new CustomServiceHost(_nativeService) : new ServiceHost(_nativeService);

                        if (!instance.UseServiceConfiguration)
                        {
                            _nativeServiceHost.AddServiceEndpoint
                            (
                                typeof(INativeCLIService),
                                DataphorServiceUtility.GetBinding(),
                                DataphorServiceUtility.BuildNativeInstanceURI(Environment.MachineName, instance.PortNumber, instance.Name)
                            );
                        }

                        _server.LogMessage("Opening Native CLI Service Host...");
                        _nativeServiceHost.Open();

                        // Start the listener
                        if (instance.ShouldListen)
                        {
                            _server.LogMessage("Starting Listener Service...");
                            _listenerServiceHost = new ListenerServiceHost(instance.OverrideListenerPortNumber, instance.RequireSecureListenerConnection, instance.AllowSilverlightClients, instance.UseServiceConfiguration);
                        }
                    }
                    catch (Exception exception)
                    {
                        _server.LogError(exception);
                        throw;
                    }
                }
                catch
                {
                    Stop();
                    throw;
                }
            }
        }