Exemplo n.º 1
0
        /// <summary>
        /// Initializes the service.
        /// </summary>
        private void InitializeService()
        {
            lock (LockObject)
            {
                if (_comarchService == null)
                {
                    _comarchService = new CLMServiceClient();
                    _comarchService.Endpoint.Address = new EndpointAddress(ServiceSettings.Address);
                    _comarchService.Endpoint.Binding.ReceiveTimeout = TimeSpan.FromSeconds(ServiceSettings.Timeout);
                    ((BasicHttpBinding)_comarchService.Endpoint.Binding).Security.Mode = GetBasicHttpSecurityMode();

                    var maxReceivedMessageSize = ServiceSettings.Parameters.GetServiceParameter <int>("MaxReceivedMessageSize");
                    ((BasicHttpBinding)_comarchService.Endpoint.Binding).MaxReceivedMessageSize = maxReceivedMessageSize > 0 ? maxReceivedMessageSize : int.MaxValue;

                    var maxBufferPoolSize = ServiceSettings.Parameters.GetServiceParameter <int>("MaxBufferPoolSize");
                    ((BasicHttpBinding)_comarchService.Endpoint.Binding).MaxBufferPoolSize = maxBufferPoolSize > 0 ? maxBufferPoolSize : int.MaxValue;

                    var maxBufferSize = ServiceSettings.Parameters.GetServiceParameter <int>("MaxBufferSize");
                    ((BasicHttpBinding)_comarchService.Endpoint.Binding).MaxBufferSize = maxBufferSize > 0 ? maxBufferSize : int.MaxValue;
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ComarchService"/> class.
        /// </summary>
        public ComarchService() : base("ComarchService")
        {
            if (ServiceSettings != null)
            {
                _clientUsername = ServiceSettings.Parameters.GetServiceParameter <string>("ClientUsername");
                _clientPassword = ServiceSettings.Parameters.GetServiceParameter <string>("ClientPassword");

                if (_comarchService == null)
                {
                    InitializeService();
                }

                if (_comarchService != null && (_comarchService.State == CommunicationState.Faulted || _comarchService.State == CommunicationState.Closed))
                {
                    lock (LockObject)
                    {
                        _comarchService = null;
                    }
                    InitializeService();
                }
            }
        }