Esempio n. 1
0
        public override void Run()
        {
            try
            {
                // Start the backup service
                RoleInstanceEndpoint externalEndPoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["BackupService"];

                var backupApiKey = RoleEnvironment.GetConfigurationSettingValue("BackupApiKey");

                this.backupServiceHost = BackupService.GetServiceHost(
                    BindingType.Tcp,
                    externalEndPoint.IPEndpoint.ToString(),
                    backupApiKey,
                    StoreLocation.LocalMachine,
                    StoreName.My,
                    "localhost");

                this.backupServiceHost.Open();

                System.Diagnostics.Trace.TraceInformation("Backup Service started on endpoint: " + externalEndPoint.IPEndpoint.ToString());
            }
            catch (Exception e)
            {
                System.Diagnostics.Trace.TraceError("Could not start Backup Service: " + e.Message);
            }

            while (true)
            {
                Thread.Sleep(10000);
            }
        }
Esempio n. 2
0
        public ActionResult Klijent(string br, string ime, string prezime)
        {
            Klijent        k  = new Klijent(br, ime, prezime);
            List <Klijent> kl = (List <Klijent>)HttpContext.Application["klijenti"];


            var binding = new NetTcpBinding();

            RoleInstanceEndpoint inputEndPoint = RoleEnvironment.Roles["WriterWorkerRole"].Instances[1].InstanceEndpoints[handlerEndPoint];
            string endpoint = String.Format("net.tcp://{0}/{1}", inputEndPoint.IPEndpoint, handlerEndPoint);

            ChannelFactory <IWriteFilm> factory = new ChannelFactory <IWriteFilm>(binding, endpoint);
            IWriteFilm proxy = factory.CreateChannel();

            foreach (Klijent item in kl)
            {
                if (item.RowKey == k.RowKey)
                {
                    proxy.AzurirajKlijenta(k);
                    return(RedirectToAction("Index"));
                }
            }
            proxy.UpisiKlijenta(k);


            return(RedirectToAction("Index"));
        }
Esempio n. 3
0
        private void CreateServiceHost()
        {
            try
            {
                var         container     = new Container();
                var         handler       = container.Get <IHandlerCaller>();
                var         animalService = new AnimalService(handler);
                ServiceHost serviceHost   = new ServiceHost(animalService);


                // TODO: add some transport security for tcp.
                NetTcpBinding        binding     = new NetTcpBinding(SecurityMode.None);
                RoleInstanceEndpoint tcpEndPoint =
                    RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["TCPENDPOINT"];
                string tcpEndpoint = String.Format("net.tcp://{0}/AnimalService",
                                                   tcpEndPoint.IPEndpoint);
                serviceHost.AddServiceEndpoint(typeof(IAnimalService), binding, tcpEndpoint);


                serviceHost.Open();
                Trace.TraceInformation("Service is Running");
            }
            catch (Exception eX)
            {
                Trace.TraceInformation("Service can not be started Error Message [" + eX.Message + "]");

                // Also kill the worker.
                OnStop();
            }
        }
Esempio n. 4
0
        public JobServer()
        {
            serviceHost = new ServiceHost(typeof(JobServerProvider));

            NetTcpBinding binding = new NetTcpBinding();

            //Default timeout je 60 sekundi pa puca na proxy tokom debug-a
            binding.OpenTimeout    = new TimeSpan(0, 10, 0);
            binding.CloseTimeout   = new TimeSpan(0, 10, 0);
            binding.SendTimeout    = new TimeSpan(0, 10, 0);
            binding.ReceiveTimeout = new TimeSpan(0, 10, 0);

            RoleInstanceEndpoint internalEndpoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints[externalEndpointName];
            string endpointAddress = String.Format("net.tcp://{0}/{1}", internalEndpoint.IPEndpoint, externalEndpointName);

            try
            {
                serviceHost.AddServiceEndpoint(typeof(INotify), binding, endpointAddress);
                Trace.TraceInformation("Host for {0} endpoint type created.", externalEndpointName);
            }
            catch (Exception e)
            {
                Trace.TraceError("ERROR: {0}", e.Message);
            }
        }
        public ActionResult Iznajmljen(string naziv, string ime, string br)
        {
            IznajmljeniFilm        i  = new IznajmljeniFilm(naziv, ime, br);
            List <IznajmljeniFilm> iz = (List <IznajmljeniFilm>)HttpContext.Application["iznajmljeni"];

            var binding = new NetTcpBinding();

            RoleInstanceEndpoint inputEndPoint = RoleEnvironment.Roles["WriterWorkerRole"].Instances[0].InstanceEndpoints[handlerEndPoint];
            string endpoint = String.Format("net.tcp://{0}/{1}", inputEndPoint.IPEndpoint, handlerEndPoint);

            ChannelFactory <IWriteFilm> factory = new ChannelFactory <IWriteFilm>(binding, endpoint);
            IWriteFilm proxy = factory.CreateChannel();

            foreach (IznajmljeniFilm item in iz)
            {
                if (item.RowKey == i.RowKey)
                {
                    proxy.AzurirajIznajmljen(i);
                    return(RedirectToAction("Index"));
                }
            }
            proxy.UpisiIznajmljen(i);


            return(RedirectToAction("Index"));
        }
        // Return the current communication channel between the external client and this web role instance;
        // Plus, return the internal channel between this web role instance and all work role instances.
        public string GetCommunicationChannel()
        {
            string thisWebRoleChannel = string.Format("You are talking to the workroles via {0}.",
                                                      OperationContext.Current.Channel.LocalAddress.Uri.ToString());

            // Contact the workrole and get the channel info
            string workRoleChannel = string.Empty;

            System.Text.StringBuilder sb = new StringBuilder();

            var roles = RoleEnvironment.Roles["WorkerRole1"];

            foreach (var instance in roles.Instances)
            {
                RoleInstanceEndpoint workRoleInternalEndPoint = instance.InstanceEndpoints["Internal"];
                NetTcpBinding        binding    = new NetTcpBinding(SecurityMode.None, false);
                EndpointAddress      myEndpoint = new EndpointAddress(String.Format("net.tcp://{0}/Internal",
                                                                                    workRoleInternalEndPoint.IPEndpoint));

                ChannelFactory <IContract> myChanFac = new ChannelFactory <WCFContract.IContract>(binding, myEndpoint);
                WCFContract.IContract      myClient  = myChanFac.CreateChannel();
                sb.Append(myClient.GetCommunicationChannel() + "\n");
            }
            workRoleChannel = sb.ToString();

            return(thisWebRoleChannel + "\n" + workRoleChannel);
        }
Esempio n. 7
0
        public StudentServer()
        {
            endpoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints[roleName];
            sh       = new ServiceHost(typeof(StudentServerProvider));

            sh.AddServiceEndpoint(typeof(IStudent), new NetTcpBinding(), $"net.tcp://{endpoint.IPEndpoint}/{roleName}");
        }
        // Return the current web role's name and instance id;
        // Plus, this web role instance talks to a work role instance via internal endpoint, and get
        // the work role's instance data.
        public string GetRoleInfo()
        {
            RoleInstance currentRoleInstance = RoleEnvironment.CurrentRoleInstance;
            string       roleName            = currentRoleInstance.Role.Name;
            string       roleInstanceID      = currentRoleInstance.Id;
            string       thisWR = string.Format("You are talking to the workroles via role {0}, instance ID {1}\n.",
                                                roleName, roleInstanceID);

            // Contact the workrole and get its info
            string workRoleInfo = string.Empty;

            System.Text.StringBuilder sb = new StringBuilder();

            var roles = RoleEnvironment.Roles["WorkerRole1"];

            foreach (var instance in roles.Instances)
            {
                RoleInstanceEndpoint WorkRoleInternalEndPoint = instance.InstanceEndpoints["Internal"];
                NetTcpBinding        binding    = new NetTcpBinding(SecurityMode.None, false);
                EndpointAddress      myEndpoint = new EndpointAddress(String.Format("net.tcp://{0}/Internal",
                                                                                    WorkRoleInternalEndPoint.IPEndpoint));

                ChannelFactory <IContract> myChanFac = new ChannelFactory <WCFContract.IContract>(binding, myEndpoint);
                WCFContract.IContract      myClient  = myChanFac.CreateChannel();
                sb.Append(myClient.GetRoleInfo() + "\n");
            }
            workRoleInfo = sb.ToString();

            return(thisWR + "\n" + workRoleInfo);
        }
Esempio n. 9
0
        public ActionResult Film(string naziv, string godina, string zanr)
        {
            Film        f       = new Film(naziv, godina, zanr);
            List <Film> filmovi = (List <Film>)HttpContext.Application["filmovi"];



            var binding = new NetTcpBinding();

            RoleInstanceEndpoint inputEndPoint = RoleEnvironment.Roles["WriterWorkerRole"].Instances[1].InstanceEndpoints[handlerEndPoint];
            string endpoint = String.Format("net.tcp://{0}/{1}", inputEndPoint.IPEndpoint, handlerEndPoint);

            ChannelFactory <IWriteFilm> factory = new ChannelFactory <IWriteFilm>(binding, endpoint);
            IWriteFilm proxy = factory.CreateChannel();

            foreach (Film item in filmovi)
            {
                if (item.RowKey == f.RowKey)
                {
                    proxy.AzurirajFilm(f);
                    return(RedirectToAction("Index"));
                }
            }
            proxy.UpisiFilm(f);


            return(RedirectToAction("Index"));
        }
Esempio n. 10
0
        public void StartService()
        {
            Type serviceBase = new Type();

            this.host = new ServiceHost(serviceBase);
            // Maybe there's a better was to do this?
            host.Faulted += this.RestartService;
            // deal with binding
            NetTcpBinding        binding      = new NetTcpBinding(SecurityMode.None);
            RoleInstanceEndpoint hostEndpoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints[endpointname];

            host.AddServiceEndpoint(
                typeof(Interface),
                binding,
                String.Format(uri, hostEndpoint.IPEndpoint)
                );
            // Start it up!
            try
            {
                host.Open();
                DebugLog.Log(String.Format("Service {0} started.", typeof(Type).Name));
            }
            catch (TimeoutException te)
            {
                DebugLog.Log(String.Format("ServiceHost open failure for {0}, Timeout: {1}", typeof(Type).Name, te.Message));
            }
            catch (CommunicationException ce)
            {
                DebugLog.Log(String.Format("ServiceHost open failure for {0}, Communication Error: {1}", typeof(Type).Name, ce.Message));
            }
        }
Esempio n. 11
0
        public JobServer()
        {
            endpoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints[name];

            sh = new ServiceHost(typeof(JobServerProvider));

            sh.AddServiceEndpoint(typeof(IContract), new NetTcpBinding(), $"net.tcp://{endpoint.IPEndpoint}/{name}");
        }
Esempio n. 12
0
        public BookstoreServer()
        {
            endpoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints[internalEndpoint];

            sh = new ServiceHost(typeof(BookstoreServerProvider));

            sh.AddServiceEndpoint(typeof(IBookstore), new NetTcpBinding(), $"net.tcp://{endpoint.IPEndpoint}/{internalEndpoint}");
        }
Esempio n. 13
0
        private void StartGameService(int retries)
        {
            if (retries == 0)
            {
                RoleEnvironment.RequestRecycle();
                return;
            }

            Trace.TraceInformation("Starting game service host...");

            _serviceHost = new ServiceHost(typeof(GameService));

            _serviceHost.Faulted += (sender, e) =>
            {
                Trace.TraceError("Host fault occured. Aborting and restarting the host. Retry count: {0}", retries);
                _serviceHost.Abort();
                StartGameService(--retries);
            };

            var binding = new NetTcpBinding(SecurityMode.None);

            RoleInstanceEndpoint externalEndPoint =
                RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["GameServer"];
            RoleInstanceEndpoint mexpEndPoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["mexport"];

            var metadatabehavior = new ServiceMetadataBehavior();

            _serviceHost.Description.Behaviors.Add(metadatabehavior);

            Binding mexBinding     = MetadataExchangeBindings.CreateMexTcpBinding();
            string  mexendpointurl = string.Format("net.tcp://{0}/GameServerMetadata", mexpEndPoint.IPEndpoint);

            _serviceHost.AddServiceEndpoint(typeof(IMetadataExchange), mexBinding, mexendpointurl);

            _serviceHost.AddServiceEndpoint(
                typeof(IGameService),
                binding,
                string.Format("net.tcp://{0}/GameServer", externalEndPoint.IPEndpoint));

            try
            {
                _serviceHost.Open();
                Trace.TraceInformation("Game service host started successfully.");
            }
            catch (TimeoutException timeoutException)
            {
                Trace.TraceError(
                    "The service operation timed out. {0}",
                    timeoutException.Message);
            }
            catch (CommunicationException communicationException)
            {
                Trace.TraceError(
                    "Could not start game service host. {0}",
                    communicationException.Message);
            }
        }
        public InternalWeatherJobServer()
        {
            NetTcpBinding        binding          = new NetTcpBinding();
            RoleInstanceEndpoint instanceEndpoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints[internalEndpointName];
            string endpoint = String.Format($"net.tcp://{instanceEndpoint.IPEndpoint}/{internalEndpointName}");

            serviceHost = new ServiceHost(typeof(WeatherJobServerProvider));
            serviceHost.AddServiceEndpoint(typeof(IWeather), binding, endpoint);
        }
Esempio n. 15
0
        public StudentServer()
        {
            RoleInstanceEndpoint roleInstance = RoleEnvironment.CurrentRoleInstance
                                                .InstanceEndpoints[endpointName];
            string adresa = $"net.tcp://{roleInstance.IPEndpoint}/{endpointName}";

            serviceHost = new ServiceHost(typeof(StudentServerProvider));
            serviceHost.AddServiceEndpoint(typeof(IStudent), binding, adresa);
        }
Esempio n. 16
0
        public JobServer()
        {
            RoleInstanceEndpoint endpoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints[externalEndpoint];
            string endpointname           = $"net.tcp://{endpoint.IPEndpoint}/{externalEndpoint}";

            sh = new ServiceHost(typeof(JobServerProvider));

            sh.AddServiceEndpoint(typeof(IJob), new NetTcpBinding(), endpointname);
        }
        public InternalServer()
        {
            NetTcpBinding        binding          = new NetTcpBinding();
            RoleInstanceEndpoint instanceEndpoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints[endPointName];
            string endpoint = $"net.tcp://{instanceEndpoint.IPEndpoint}/{endPointName}";

            serviceHost = new ServiceHost(typeof(InternalServerProvider));
            serviceHost.AddServiceEndpoint(typeof(IForwardMessage), binding, endpoint);
        }
Esempio n. 18
0
        public JobServer2()
        {
            RoleInstanceEndpoint roleInstanceEndpoint = RoleEnvironment
                                                        .CurrentRoleInstance.InstanceEndpoints[endpointName];
            string adresa = $"net.tcp://{roleInstanceEndpoint.IPEndpoint}/{endpointName}";

            serviceHost = new ServiceHost(typeof(JobServiceProvider2));
            serviceHost.AddServiceEndpoint(typeof(IForward), binding, adresa);
        }
Esempio n. 19
0
        internal static void ListEndpointDetails(RoleInstanceEndpoint endpoint)
        {
            if (endpoint == null)
            {
                throw new ArgumentNullException("endpoint", "No RoleInstanceEndpoint data provided");
            }

            Trace.TraceInformation("Role={0} Instance={1} Address={2} Port={3}",
                                   endpoint.RoleInstance.Role.Name, endpoint.RoleInstance.Id, endpoint.IPEndpoint.Address, endpoint.IPEndpoint.Port);
        }
Esempio n. 20
0
        public PartialJobServer()
        {
            RoleInstanceEndpoint inputEndPoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints[endPointName];
            string endpoint = String.Format("net.tcp://{0}/{1}", inputEndPoint.IPEndpoint, endPointName);

            serviceHost = new ServiceHost(typeof(PartialJobServerProvider));
            NetTcpBinding binding = new NetTcpBinding();

            serviceHost.AddServiceEndpoint(typeof(IJobInternal), binding, endpoint);
        }
Esempio n. 21
0
        public StudentServer()
        {
            NetTcpBinding binding = new NetTcpBinding();

            instanceEndpoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints[externalEndpointName];
            string endpoint = String.Format($"net.tcp://{instanceEndpoint.IPEndpoint}/{externalEndpointName}");

            serviceHost = new ServiceHost(typeof(StudentProvider));
            serviceHost.AddServiceEndpoint(typeof(IStudents), binding, endpoint);
        }
        /// <summary>
        /// Attaches the specified owner.
        /// </summary>
        /// <param name="owner">The owner.</param>
        public void Attach(ServiceHostBase owner)
        {
            this.owner = owner;

            //This could be done using the owner, you can read it near the bottom of this code-file
            endpointAzure = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["RoutingServiceMain"];

            //start the fun
            this.Init();
        }
Esempio n. 23
0
        public NotifyOthersServer()
        {
            RoleInstanceEndpoint inputEndPoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints[endPointName];
            string endpoint = String.Format("net.tcp://{0}/{1}", inputEndPoint.IPEndpoint, endPointName);

            serviceHost = new ServiceHost(typeof(NotifyOthersProvider));
            NetTcpBinding binding = new NetTcpBinding();

            serviceHost.AddServiceEndpoint(typeof(INotifyOthers), binding, endpoint);
        }
Esempio n. 24
0
        public CoordinatorServer()
        {
            endpoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints[endpointName];

            sh = new ServiceHost(typeof(CoordinatorServerProvider));

            sh.AddServiceEndpoint(typeof(IClientInteraction), new NetTcpBinding(), $"net.tcp://{endpoint.IPEndpoint}/{endpointName}");

            Trace.WriteLine($"ServiceHost {endpointName} is created on {endpoint.IPEndpoint}");
        }
Esempio n. 25
0
        public Server()
        {
            //External
            RoleInstanceEndpoint inputEndPoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["InputRequest"];
            string endpoint = String.Format("net.tcp://{0}/{1}", inputEndPoint.IPEndpoint, _externalEndpointName);

            _serviceHostExternal = new ServiceHost(typeof(ServerProvider));
            NetTcpBinding binding = new NetTcpBinding();
            _serviceHostExternal.AddServiceEndpoint(typeof(IJobReader), binding, endpoint);
        }
Esempio n. 26
0
        public void JobServer()
        {
            NetTcpBinding binding = new NetTcpBinding();

            RoleInstanceEndpoint roleInstance = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints[externalEndpointName];

            serviceHost = new ServiceHost(typeof(Service));

            serviceHost.AddServiceEndpoint(typeof(IQueueRequest_WebRole), binding, String.Format("net.tcp://{0}/{1}", roleInstance, externalEndpointName));
        }
Esempio n. 27
0
        public LogProvider()
        {
            RoleInstanceEndpoint inputEndPoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints[externalEndpointName];
            string endpoint = String.Format("net.tcp://{0}/{1}", inputEndPoint.IPEndpoint, externalEndpointName);

            serviceHost = new ServiceHost(typeof(LogImplementacija));
            NetTcpBinding binding = new NetTcpBinding();

            serviceHost.AddServiceEndpoint(typeof(ILogcs), binding, endpoint);
        }
Esempio n. 28
0
        public JobServer()
        {
            NetTcpBinding binding = new NetTcpBinding();

            instanceEndpoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints[externalEndpointName];
            string endpoint = String.Format($"net.tcp://{instanceEndpoint.IPEndpoint}/{externalEndpointName}");

            serviceHost = new ServiceHost(typeof(JobServerProvider));
            serviceHost.AddServiceEndpoint(typeof(IBookstore), binding, endpoint);
            tableHelper.Bookstore();
        }
        public void JobServer()
        {
            NetTcpBinding binding = new NetTcpBinding();

            RoleInstanceEndpoint roleInstance = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints[externalEndpoint];


            serviceHost = new ServiceHost(typeof(PartialServerProvider));

            serviceHost.AddServiceEndpoint(typeof(IBlue1_Partial), binding, String.Format("net.tcp://{0}/{1}", roleInstance.IPEndpoint, externalEndpoint));
        }
Esempio n. 30
0
        public JobServer()
        {
            RoleInstanceEndpoint inputEndPoint = RoleEnvironment.
                                                 CurrentRoleInstance.InstanceEndpoints[_externalEndPointName];
            string endpoint = ($"net.tcp://{inputEndPoint.IPEndpoint}/{_externalEndPointName}");

            _serviceHost = new ServiceHost(typeof(JobServerProvider));
            NetTcpBinding binding = new NetTcpBinding();

            _serviceHost.AddServiceEndpoint(typeof(IJob), binding, endpoint);
        }
 private static string EndpointToUrl( RoleInstanceEndpoint endpoint )
 {
     return string.Format("{0}://{1}:{2}", endpoint.Protocol, endpoint.IPEndpoint.Address, endpoint.IPEndpoint.Port);
 }