예제 #1
0
        protected virtual void Dispose(bool disposing)
        {
            if (!disposed)
            {
                if (disposing)
                {
                    try
                    {
                        _autoTaskClient.Close();
                    }
                    catch (CommunicationException e)
                    {
                        _autoTaskClient.Abort();
                    }
                    catch (TimeoutException e)
                    {
                        _autoTaskClient.Abort();
                    }
                    catch (Exception e)
                    {
                        _autoTaskClient.Abort();
                        throw;
                    }
                }

                disposed = true;
            }
        }
예제 #2
0
        public Client(string username, string password, ILogger logger = null)
        {
            _logger = logger ?? new NullLogger <Client>();
            var binding = new BasicHttpBinding
            {
                SendTimeout            = new TimeSpan(0, 0, 0, 0, 100000),
                OpenTimeout            = new TimeSpan(0, 0, 0, 0, 100000),
                MaxReceivedMessageSize = 10000,
                ReaderQuotas           =
                {
                    MaxStringContentLength = 10000,
                    MaxDepth       = 10000,
                    MaxArrayLength = 10000
                },
                Security = new BasicHttpSecurity
                {
                    Mode      = BasicHttpSecurityMode.Transport,
                    Transport = new HttpTransportSecurity
                    {
                        ClientCredentialType = HttpClientCredentialType.None,
                        ProxyCredentialType  = HttpProxyCredentialType.None,
                    }
                }
            };
            var endpoint = new EndpointAddress("https://webservices1.autotask.net/ATServices/1.5/atws.asmx");

            _autoTaskClient = new ATWSSoapClient(binding, endpoint);
            var zoneInfo = _autoTaskClient.getZoneInfoAsync(new getZoneInfoRequest(username)).GetAwaiter().GetResult();

            // Create the binding.
            // must use BasicHttpBinding instead of WSHttpBinding
            // otherwise a "SOAP header Action was not understood." is thrown.
            var myBinding = new BasicHttpBinding
            {
                Security =
                {
                    Mode      = BasicHttpSecurityMode.Transport,
                    Transport = { ClientCredentialType = HttpClientCredentialType.Basic }
                },
                MaxReceivedMessageSize = 2147483647
            };

            // Must set the size otherwise
            //The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.

            // Create the endpoint address.
            var ea = new EndpointAddress(zoneInfo.getZoneInfoResult.URL);

            _autoTaskClient.Close();
            _autoTaskClient = new ATWSSoapClient(myBinding, ea);

            AutoTaskLogger = new AutoTaskLogger(_logger);
            _autoTaskClient.Endpoint.EndpointBehaviors.Add(AutoTaskLogger);

            _autoTaskClient.ClientCredentials.UserName.UserName = username;
            _autoTaskClient.ClientCredentials.UserName.Password = password;

            // have no clue what this does.
            _autotaskIntegrations = new AutotaskIntegrations();
        }
예제 #3
0
        private bool disposedValue = false;         // To detect redundant calls

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    // Not an actual dispose, but happens when we get disposed to ensure closing the client nicely
                    _clientDoNotUseDirectly?.Close();
                }
                disposedValue = true;
            }
        }
예제 #4
0
        private async Task <ATWSSoap> GetClientAsync()
        {
            if (_clientDoNotUseDirectly != null)
            {
                return(_clientDoNotUseDirectly);
            }

            var client   = new ATWSSoapClient();
            var zoneInfo = await client.getZoneInfoAsync(new getZoneInfoRequest(_configuration.Username)).ConfigureAwait(false);

            // Create the binding.
            // must use BasicHttpBinding instead of WSHttpBinding
            // otherwise a "SOAP header Action was not understood." is thrown.
            var myBinding = new BasicHttpBinding();

            myBinding.Security.Mode = BasicHttpSecurityMode.Transport;
            myBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;

            // Must set the size otherwise
            //The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.
            myBinding.MaxReceivedMessageSize = 2147483647;

            // Create the endpoint address.
            var ea = new EndpointAddress(zoneInfo.getZoneInfoResult.URL);

            client.Close();

            client = new ATWSSoapClient(myBinding, ea);
            client.ClientCredentials.UserName.UserName = _configuration.Username;
            client.ClientCredentials.UserName.Password = _configuration.Password;

            //Autotask is implementing mandatory tracking identifiers for
            //Integration developers selling or offering integrations into the Autotask channel.

            _autotaskIntegrations = new AutotaskIntegrations {
                IntegrationCode = _configuration.IntegrationCode
            };
            return(_clientDoNotUseDirectly = client);
        }
예제 #5
0
        private async Task <ATWSSoapClient> GetATWSSoapClientAsync(CancellationToken cancellationToken)
        {
            if (_autoTaskClient != null)
            {
                return(_autoTaskClient);
            }

            var binding = new BasicHttpBinding
            {
                SendTimeout            = new TimeSpan(0, 0, 0, 0, _clientOptions.SendTimeoutMs),
                OpenTimeout            = new TimeSpan(0, 0, 0, 0, _clientOptions.OpenTimeoutMs),
                MaxReceivedMessageSize = 10000,
                ReaderQuotas           =
                {
                    MaxStringContentLength = 10000,
                    MaxDepth       = 10000,
                    MaxArrayLength = 10000
                },
                Security = new BasicHttpSecurity
                {
                    Mode      = BasicHttpSecurityMode.Transport,
                    Transport = new HttpTransportSecurity
                    {
                        ClientCredentialType = HttpClientCredentialType.None,
                        ProxyCredentialType  = HttpProxyCredentialType.None,
                    }
                }
            };

            string endpointAddressUrl;

            if (_clientOptions.ServerId is null)
            {
                var endpoint = new EndpointAddress("https://webservices.autotask.net/ATServices/1.6/atws.asmx");
                using var zoneInfoAutoTaskClient = new ATWSSoapClient(binding, endpoint);

                var zoneInfo = await zoneInfoAutoTaskClient
                               .getZoneInfoAsync(new getZoneInfoRequest(_username))
                               .WithCancellation(cancellationToken)
                               .ConfigureAwait(false);

                zoneInfoAutoTaskClient.Close();
                endpointAddressUrl = zoneInfo.getZoneInfoResult.URL;
            }
            else
            {
                endpointAddressUrl = $"https://webservices{_clientOptions.ServerId}.autotask.net/ATServices/1.6/atws.asmx";
            }

            // Create the binding.
            // must use BasicHttpBinding instead of WSHttpBinding
            // otherwise a "SOAP header Action was not understood." is thrown.
            var myBinding = new BasicHttpBinding
            {
                Security =
                {
                    Mode      = BasicHttpSecurityMode.Transport,
                    Transport = { ClientCredentialType = HttpClientCredentialType.Basic }
                },
                MaxReceivedMessageSize = 2147483647
            };

            // Must set the size otherwise
            //The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.

            // Create the endpoint address.
            var ea = new EndpointAddress(endpointAddressUrl);

            var autoTaskClient = new ATWSSoapClient(myBinding, ea);

            autoTaskClient.Endpoint.EndpointBehaviors.Add(AutoTaskLogger);
            autoTaskClient.ClientCredentials.UserName.UserName = _username;
            autoTaskClient.ClientCredentials.UserName.Password = _password;
            return(_autoTaskClient = autoTaskClient);
        }