NFS-E CONFIGURACAO HTTPWEBREQUEST

 Tópico anterior Próximo tópico Novo tópico

NFS-E CONFIGURACAO HTTPWEBREQUEST

C#

 Compartilhe  Compartilhe  Compartilhe
#497270 - 22/06/2021 20:20:41

IVANDGT100
BELO HORIZONTE
Cadast. em:Abril/2014


Mestre Kerplunk, assisti ao vídeo e foi muito ilustrativo. Mas seria importante efetuar a comunicação sem utilizar o 'Web Service Reference'.
Apenas utilizando o HttpWebRequest. Creio que estou errando na configuração dos parâmetros do HttpWebRequest... por favor me ajude!


Gentileza gera Gentileza - Profeta Gentileza


#497486 - 11/07/2021 15:05:48

IVANDGT100
BELO HORIZONTE
Cadast. em:Abril/2014


Boa tarde colegas e ao professor Kerplunk!
Senhores observando as informações do professor Kerplunk consegui obter êxito!
Abaixo anexo o código que está operante em NET CORE, comunicando com o BHISS Digital!
Novamente obrigado à todos pela ajuda!



    public class CaWebNfse
    {

        public X509Certificate2 gcer;
        public DataSet gds;
        public string gfil = '';                    //http ret file write
        public string gret = '';                    //http ret
        public string gsoap = '';                   //soap msg
        public string gsoapAction = '';             //soap action
        public string gurl = '';                    //http url
        public string gurl2 = '';

        public HttpWebRequest ghttpWR;              //http cli


        //-------------------------------------------------
        //
        //WEBSERVICE COMUNICACAO
        //
        //-------------------------------------------------
        public string QxHttpNfs(XmlNode xml)
        {
            try
            {
                ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

                gret = string.Empty;
                gsoap = xml.OuterXml;

                QxCfg(gurl);                                                            //ghttpWR configura, visualizacao mais clara

                Stream reqStream = ghttpWR.GetRequestStream();
                StreamWriter streamWriter = new StreamWriter(reqStream);
                streamWriter.Write(gsoap, 0, Encoding.ASCII.GetBytes(gsoap).Length);
                streamWriter.Close();

                WebResponse webResponse = ghttpWR.GetResponse();
                Stream respStream = webResponse.GetResponseStream();
                StreamReader streamReader = new StreamReader(respStream);

                gret = streamReader.ReadToEnd();
                gret.QpXml().QpArqTxt(gfil);
                return gret;
            }
            catch (WebException ex)
            {
                string s1 = gurl;
                string s3 = '';
                string x1 = new FcXml().Qprint(gsoap);
                if (ex.InnerException != null) s3 = ex.InnerException.Message;          

                if (ex.Response == null) new FcDic().Qthrow('web.200', s3);
                using (var stream = ex.Response.GetResponseStream())
                using (var reader = new StreamReader(stream))
                {
                    string s2 = reader.ReadToEnd();
                    new FcDic().Qthrow('web.200', s2);                                  //força throw padrao
                }
                throw;
            }
        }
        public void QxCfg(string url1)
        {
            ghttpWR = (HttpWebRequest)WebRequest.Create(url1);                          
                                                                                        
            ghttpWR.PreAuthenticate = true;
            ghttpWR.ServicePoint.Expect100Continue = false;                            
            ghttpWR.CookieContainer = new CookieContainer();
            ghttpWR.Timeout = 30000;

            ghttpWR.Headers.Add('SOAPAction: ' + gsoapAction);
            ghttpWR.ContentType = 'application/soap+xml;charset=utf-8';
            ghttpWR.ContentType = 'text/xml;charset=UTF-8';                             //NESTE PONTO ATENCAO!!!!!
            ghttpWR.Method = WebRequestMethods.Http.Post;
            ghttpWR.Accept = 'text/xml';

            ghttpWR.KeepAlive = true;
            ghttpWR.ClientCertificates.Add(gcer);
            ghttpWR.UseDefaultCredentials = true;                                      

            ghttpWR.ContentLength = Encoding.ASCII.GetBytes(gsoap).Length;
            ghttpWR.Proxy = WebRequest.GetSystemWebProxy();
            ghttpWR.SendChunked = false;                                                
        }


    }



Gentileza gera Gentileza - Profeta Gentileza


 Tópico anterior Próximo tópico Novo tópico


Tópico encerrado, respostas não sao permitidas
Encerrado por IVANDGT100 em 11/07/2021 15:06:16