internal async static Task <MessageServiceClient> CreateMessageServiceClient(string ServiceConnectionUri)
        {
            var messageServiceClient = new MessageServiceClient(ServiceConnectionUri);

            HttpClientHandler handler = new HttpClientHandler();

            handler.UseDefaultCredentials = true;

            using (var client = new HttpClient(handler))
            {
                HttpResponseMessage response = await client.GetAsync(ServiceConnectionUri);

                if (response.IsSuccessStatusCode)
                {
                    return(messageServiceClient);
                }
                else
                {
                    throw new Exception("Unable To connect to WebService Uri, " + ServiceConnectionUri + ", " + response.RequestMessage);
                }
            }
        }
示例#2
0
        protected override async void OnStart(string[] args)
        {
            AppLogging.Instance.Info("Starting Messaging Broker Service");
            try
            {
                this.ServiceConfiguration = await Service_Start.ServiceConfiguration.GetServiceConfiguration();
            }
            catch (Exception ex)
            {
                AppLogging.Instance.Error(ex);
            }

            AppLogging.Instance.Info("Connecting to Database, " + ServiceConfiguration.DatabaseConnectionString);

            try
            {
                this.DataBaseContext = new NebulusContext(this.ServiceConfiguration.DatabaseConnectionString);
            }
            catch (Exception ex)
            {
                AppLogging.Instance.Error("Error Connecting to database", ex);
            }

            AppLogging.Instance.Info("Connecting to Messaging WebService, " + ServiceConfiguration.NebulusMessageWebServiceUri);
            try
            {
                this.MessageWebServiceClient = await Service_Code.MessageServiceClient.CreateMessageServiceClient(NebulusMessageBroker.Properties.Settings.Default.ServiceConfigConnectionString + "/api/service/PostMessage");
            }
            catch (Exception ex)
            {
                AppLogging.Instance.Error(ex);
            }

            System.Timers.Timer timer = new System.Timers.Timer();
            timer.Interval = 30000;
            timer.Elapsed += new System.Timers.ElapsedEventHandler(this.OnTimer);
            timer.Start();
        }