Ejemplo n.º 1
0
        /// <summary>
        /// Constructor de la Clase ConexionSunat
        /// </summary>
        /// <param name="endPointServicio">Nombre del Endpoint</param>
        /// <param name="MS">Objeto MainSettings - Contiene ruc, user y pass de Sunat</param>
        public SunatConnection(string endPointServicio, MainSettings MS)
        {
            System.Net.ServicePointManager.UseNagleAlgorithm = true;
            System.Net.ServicePointManager.Expect100Continue = false;
            System.Net.ServicePointManager.CheckCertificateRevocationList = true;
            //System.Net.ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(IgnoreCertificateErrorHandler);

            this.MS = MS;
            MS.GeneraLog.EnvioSunat01("URL: " + MS.UEnv);
            if (MS.Envi == "DEV")
            {
                EndPointServicio = "DEV" + endPointServicio;
                //string urldev = @"https://e-beta.sunat.gob.pe:443/ol-ti-itcpfegem-beta/billService";
                //string urldev = @"https://www.sunat.gob.pe:443/ol-ti-itcpfegem/billService";
                _proxyDEV = new SunatDEV.billServiceClient(EndPointServicio, MS.UEnv);
                // Agregamos el behavior configurado para soportar WS-Security.
                var behavior = new PasswordDigestBehavior(string.Concat(MS.RucNumber, MS.SunatUsr), MS.SunatPwd);
                _proxyDEV.Endpoint.EndpointBehaviors.Add(behavior);
            }
            if (MS.Envi == "HML")
            {
                EndPointServicio = "HML" + endPointServicio;
                _proxyPRD        = new SunatPRD.billServiceClient(EndPointServicio, MS.UEnv);
                // Agregamos el behavior configurado para soportar WS-Security.

                //var behavior = new PasswordDigestBehavior(string.Concat(MS.UserAltern.Length == 11 ? MS.UserAltern : MS.RucNumber, MS.SunatUsr), MS.SunatPwd);
                var behavior = new PasswordDigestBehavior(string.Concat(MS.RucNumber, MS.SunatUsr), MS.SunatPwd);
                _proxyPRD.Endpoint.EndpointBehaviors.Add(behavior);
            }
            if (MS.Envi == "PRD")
            {
                //if ("01|03|RC|RA".Contains(MS.DocumentType))
                //{
                EndPointServicio = "PRD" + endPointServicio;
                _proxyPRD        = new SunatPRD.billServiceClient(EndPointServicio, MS.UEnv);
                // Agregamos el behavior configurado para soportar WS-Security.
                //var behavior = new PasswordDigestBehavior(string.Concat(MS.RucNumber, MS.SunatUsr), MS.SunatPwd);
                var behavior = new PasswordDigestBehavior(string.Concat(MS.UserAltern.Length == 11 ? MS.UserAltern : MS.RucNumber, MS.SunatUsr), MS.SunatPwd);
                _proxyPRD.Endpoint.EndpointBehaviors.Add(behavior);
                //}

                //if ("20|40".Contains(MS.DocumentType))
                //{
                //    EndPointServicio = "PRD" + endPointServicio;
                //    _proxyPRDr = new SunatPRDr.billServiceClient(EndPointServicio);
                //    //_proxyPRDr.ClientCredentials.CreateSecurityTokenManager();
                //    //_proxyPRDr.ClientCredentials.UserName.UserName = string.Concat(MS.RucNumber, MS.SunatUsr);
                //    //_proxyPRDr.ClientCredentials.UserName.Password = MS.SunatPwd;

                //    // Agregamos el behavior configurado para soportar WS-Security.
                //    var behavior = new PasswordDigestBehavior(string.Concat(MS.RucNumber, MS.SunatUsr), MS.SunatPwd);
                //    _proxyPRDr.Endpoint.EndpointBehaviors.Add(behavior);
                //}
            }
        }
Ejemplo n.º 2
0
        private bool _disposedValue; // To detect redundant calls

        protected virtual void Dispose(bool disposing)
        {
            if (!_disposedValue)
            {
                if (disposing)
                {
                    _proxyDEV = null;
                }

                _disposedValue = true;
            }
        }