Exemple #1
0
        private void InitializeConnection()
        {
            //Initialize WCF Communication
            try
            {
                _uiSyncContext = SynchronizationContext.Current;
                //WSHttpBinding binding = new WSHttpBinding();
                Uri address = new Uri("http://localhost:6666/QueueMessageService/service");
                //EndpointAddress endpoint = new EndpointAddress(address);



                InstanceContext instanceContext = new InstanceContext(this);

                //_MessageService = new ServiceReference.ContractClient(instanceContext, "WSDualHttpBinding_Contract", endpoint);
                _QueueMessage = new QueueSystemServiceReference.ContractClient(instanceContext, "WSDualHttpBinding_Contract");

                _QueueMessage.Open();

                //using (_QueueMessage = new QueueSystemServiceReference.ContractClient(instanceContext, "WSDualHttpBinding_Contract"))
                //{
                //    _QueueMessage.Open();

                //    serviceRequest.DynamicInvoke();
                //}
            }
            catch (Exception ex)
            {
                if (!DesignerProperties.GetIsInDesignMode(new System.Windows.DependencyObject()))
                {
                    serviceConnectionNotEstablished = ex;
                    MessageBox.Show("Connection to the service could no be established", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
Exemple #2
0
        private void InitializeConnection()
        {
            //Initialize WCF Communication
            try
            {
                _uiSyncContext = SynchronizationContext.Current;
                InstanceContext instanceContext = new InstanceContext(this);

                //without app.config settings
                WSDualHttpBinding binding = new WSDualHttpBinding();
                binding.OpenTimeout    = new TimeSpan(0, 0, 5);
                binding.SendTimeout    = new TimeSpan(0, 0, 5);
                binding.ReceiveTimeout = new TimeSpan(0, 0, 5);
                binding.CloseTimeout   = new TimeSpan(0, 0, 1);
                string          serviceURL = ParametersHelper.Read().ServiceAddress;
                Uri             address    = new Uri(serviceURL);
                EndpointAddress endpoint   = new EndpointAddress(address, EndpointIdentity.CreateDnsIdentity("localhost"));

                _QueueMessage = new QueueSystemServiceReference.ContractClient(instanceContext, binding, endpoint);

                if (!ConnectionStatus)
                {
                    _QueueMessage.Open();
                    ConnectionStatus = true;

                    //counter to count fail livebit messages and stop livebit sending after desired fault messages
                    liveBitFailCounter = new Counter(ParametersHelper.Read().ServerConnectionRetries);
                    liveBitFailCounter.ThresholdReached += LiveBitFailCounter_ThresholdReached;
                    StartLiveBit();
                }
            }
            catch (System.ServiceModel.EndpointNotFoundException)
            {
                RetryConnectionTimer          = new System.Timers.Timer(5000);
                RetryConnectionTimer.Elapsed += RetryConnectionTimer_Elapsed;
                RetryConnectionTimer.Start();
            }
            catch (Exception ex)
            {
                if (!DesignerProperties.GetIsInDesignMode(new System.Windows.DependencyObject()))
                {
                    serviceConnectionNotEstablished = ex;
                    MessageBox.Show(StaticDetails.OpenServerConnectionErrorMessage, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }