public static ITRetConsReciNFe ConsultarProcessamentoEnvelope( System.Web.Services.Protocols.SoapHttpClientProtocol oServico, ITConsReciNFe oConsReciNFe, Parametro oParam, VersaoXML versao) { return((ITRetConsReciNFe)XMLUtils.LoadXML(ExecutaServico(oServico, oConsReciNFe, oParam), versao, "TRetConsReciNFe")); }
public static ITRetEnvEvento EnviarEnvelopeEvento( System.Web.Services.Protocols.SoapHttpClientProtocol oServico, ITEnvEvento oEnvEvento, Parametro oParam, VersaoXML versao) { return((ITRetEnvEvento)XMLUtils.LoadXML(ExecutaServico(oServico, oEnvEvento, oParam), versao, "TRetEnvEvento")); }
public static void InicializaServico( System.Web.Services.Protocols.SoapHttpClientProtocol oServico, Parametro oParam) { X509Certificate2 certificadoX509 = Certificado.BuscaNome(oParam.certificado, oParam.usaWService, oParam.tipoBuscaCertificado); oServico.ClientCertificates.Clear(); oServico.ClientCertificates.Add(certificadoX509); if (oParam.prx) { oServico.Proxy = new WebProxy(oParam.prxUrl, true); oServico.Proxy.Credentials = new NetworkCredential(oParam.prxUsr, oParam.prxPsw, oParam.prxDmn); } else { oServico.Credentials = System.Net.CredentialCache.DefaultCredentials; } oServico.Timeout = (int)oParam.timeout; oServico.InitializeLifetimeService(); // forçar aceitação de todos os certificados dos servidores da SEFAZ // independentemente de ter a cadeia de certificação instalada System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); }; //permitir os protocolos: TLS1.0 TLS1.1 TLS1.2 System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; }
internal WebMethod(SoapHttpClientProtocol svc, MethodInfo methodInfo) { _svc = svc; _methodInfo = methodInfo; string argType = CustomProxyGenerator.GetMethodArgType(methodInfo.Name); _arg = Activator.CreateInstance(svc.GetType().Assembly.GetType(argType)); }
public static ITRetInutNFe InutilizarNFe( System.Web.Services.Protocols.SoapHttpClientProtocol oServico, ITInutNFe oInutNFe, Parametro oParam, VersaoXML versao) { return((ITRetInutNFe)XMLUtils.CarregaXML_STR(ExecutaServico(oServico, oInutNFe, oParam), versao, "TRetInutNFe")); }
// // Constructs the SoapClientMessage // internal SoapClientMessage (SoapHttpClientProtocol client, SoapMethodStubInfo msi, string url, object [] parameters) { this.MethodStubInfo = msi; this.client = client; this.url = url; Parameters = parameters; }
public static ITRetConsSitNFe ConsultarSituacaoNFe( System.Web.Services.Protocols.SoapHttpClientProtocol oServico, ITConsSitNFe oConsSitNFe, Parametro oParam, VersaoXML versao) { return((ITRetConsSitNFe)XMLUtils.CarregaXML_STR(ExecutaServico(oServico, oConsSitNFe, oParam), versao, "TRetConsSitNFe")); }
public static ITRetConsStatServ ConsultarStatusServidor( System.Web.Services.Protocols.SoapHttpClientProtocol oServico, ITConsStatServ oConsStatServ, Parametro oParam, VersaoXML versao) { return((ITRetConsStatServ)XMLUtils.CarregaXML_STR(ExecutaServico(oServico, oConsStatServ, oParam), versao, "TRetConsStatServ")); }
public static ITRetEnviNFe EnviarEnvelope( System.Web.Services.Protocols.SoapHttpClientProtocol oServico, ITEnviNFe oEnviNFe, Parametro oParam, VersaoXML versao) { return((ITRetEnviNFe)XMLUtils.CarregaXML_STR(ExecutaServico(oServico, oEnviNFe, oParam), versao, "TRetEnviNFe")); }
// // Constructs the SoapClientMessage // internal SoapClientMessage (SoapHttpClientProtocol client, SoapMethodStubInfo msi, string url, object [] parameters) { this.MethodStubInfo = msi; this.client = client; this.url = url; Parameters = parameters; if (SoapVersion == SoapProtocolVersion.Soap12) ContentType = "application/soap+xml"; }
public static void Configure(SoapHttpClientProtocol gateway) { if (gateway == null) throw new ArgumentNullException("gateway"); string url = _config.GetValueFromAppConfig<string>(gateway.GetType().FullName, null); if (string.IsNullOrEmpty(url)) throw new ConfigurationErrorsException(string.Format(CultureInfo.CurrentCulture, "The configuration key {0} for this gateway is missing", gateway.GetType().FullName)); gateway.Url = url; }
protected void ConfigureProxy(SoapHttpClientProtocol _client) { if (config.ConfigWrapper.GetAppSetting("proxy") != null) { _client.UseDefaultCredentials = false; _client.PreAuthenticate = true; _client.Proxy = new WebProxy(config.ConfigWrapper.GetAppSetting("proxy"), true); _client.Proxy.Credentials = new NetworkCredential(_proxy_user, _proxy_pass, _proxy_domain); } }
public static KeyValuePair <string, ITRetConsStatServ> Interface_ConsultarStatusServidor( System.Web.Services.Protocols.SoapHttpClientProtocol oServico, ITConsStatServ oConsStatServ, Parametro oParam, VersaoXML versao) { var Key = ExecutaServico(oServico, oConsStatServ, oParam); try { var Value = (ITRetConsStatServ)XMLUtils.LoadXML(Key, versao, "TRetConsStatServ"); return(new KeyValuePair <string, ITRetConsStatServ>(Key, Value)); } catch (Exception ex) { Key = ex.Message + " - " + Key; return(new KeyValuePair <string, ITRetConsStatServ>(Key, null)); } }
public static KeyValuePair <string, ITRetConsSitNFe> Interface_ConsultarSituacaoNFe( System.Web.Services.Protocols.SoapHttpClientProtocol oServico, ITConsSitNFe oConsSitNFe, Parametro oParam, VersaoXML versao) { var Key = ExecutaServico(oServico, oConsSitNFe, oParam); try { var Value = (ITRetConsSitNFe)XMLUtils.CarregaXML_STR(Key, versao, "TRetConsSitNFe"); return(new KeyValuePair <string, ITRetConsSitNFe>(Key, Value)); } catch (Exception ex) { Key = ex.Message + " - " + Key; return(new KeyValuePair <string, ITRetConsSitNFe>(Key, null)); } }
public static KeyValuePair <string, ITRetInutNFe> Interface_InutilizarNFe( System.Web.Services.Protocols.SoapHttpClientProtocol oServico, ITInutNFe oInutNFe, Parametro oParam, VersaoXML versao) { var Key = ExecutaServico(oServico, oInutNFe, oParam); try { var Value = (ITRetInutNFe)XMLUtils.LoadXML(Key, versao, "TRetInutNFe"); return(new KeyValuePair <string, ITRetInutNFe>(Key, Value)); } catch (Exception ex) { Key = ex.Message + " - " + Key; return(new KeyValuePair <string, ITRetInutNFe>(Key, null)); } }
//chamadas com retornos em string public static KeyValuePair <string, ITRetEnvEvento> Interface_EnviarEnvelopeEvento( System.Web.Services.Protocols.SoapHttpClientProtocol oServico, ITEnvEvento oEnvEvento, Parametro oParam, VersaoXML versao) { var Key = ExecutaServico(oServico, oEnvEvento, oParam); try { var Value = (ITRetEnvEvento)XMLUtils.CarregaXML_STR(Key, versao, "TRetEnvEvento"); return(new KeyValuePair <string, ITRetEnvEvento>(Key, Value)); } catch (Exception ex) { Key = ex.Message + " - " + Key; return(new KeyValuePair <string, ITRetEnvEvento>(Key, null)); } }
public static SoapHttpClientProtocol GetWebService(SoapHttpClientProtocol ws) { string url = ws.Url.ToLower(); int LastSlash = url.LastIndexOf("/"); string UrlDirectory = url.Substring(0, LastSlash + 1); string app = ConfigurationManager.Instance.WebServiceURL.Trim(); if (app.Length == 0 || app.ToLower() == UrlDirectory) { return ws; } else { ws.Url = url.Replace(UrlDirectory, app); return ws; } }
public void PrepareProxy(SoapHttpClientProtocol proxy) { string smarterUrl = SmarterUrl; int idx = proxy.Url.LastIndexOf("/"); // strip the last slash if any if (smarterUrl[smarterUrl.Length - 1] == '/') smarterUrl = smarterUrl.Substring(0, smarterUrl.Length - 1); proxy.Url = smarterUrl + proxy.Url.Substring(idx); }
/// <summary> /// Initializes the <see cref="T:System.ServiceModel.ServiceHost" /> /// </summary> /// <param name="compoundTemplateWebService">Target CompoundTemplateWebService to proxy</param> protected void Initialize(SoapHttpClientProtocol compoundTemplateWebService) { Uri address = new Uri("http://localhost:9090/templating/compoundtemplatewebservice.asmx"); ServiceHost mServiceHost = new ServiceHost(Service); BasicHttpBinding binding = new BasicHttpBinding() { HostNameComparisonMode = HostNameComparisonMode.Exact, OpenTimeout = TimeSpan.FromMinutes(5), CloseTimeout = TimeSpan.FromMinutes(5), SendTimeout = TimeSpan.FromMinutes(5), ReceiveTimeout = TimeSpan.FromMinutes(5), MaxReceivedMessageSize = 2097152 // 2 MB }; binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly; binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic; mServiceHost.Credentials.UserNameAuthentication.UserNamePasswordValidationMode = UserNamePasswordValidationMode.Custom; mServiceHost.Credentials.UserNameAuthentication.CustomUserNamePasswordValidator = new CredentialsPassThrough(compoundTemplateWebService); mServiceHost.AddServiceEndpoint(ImplementedContract, binding, address); // Listen for requests mServiceHost.Open(); }
internal SoapClientMessage(SoapHttpClientProtocol protocol, SoapClientMethod method, string url) { this.method = method; this.protocol = protocol; this.url = url; }
/// <summary> /// Initializes a new instance of the <see cref="CredentialsPassThrough"/> class. /// </summary> /// <param name="compoundTemplateWebService">Target CompoundTemplateWebService to proxy for.</param> public CredentialsPassThrough(SoapHttpClientProtocol compoundTemplateWebService) : base() { mCompoundTemplateWebService = compoundTemplateWebService; }
public void ApplyProxy(SoapHttpClientProtocol request) { var proxy = WebServiceProxy; if (proxy != null) { request.Proxy = proxy; } }
public ServidorFacturaElectronica( SoapHttpClientProtocol wsfe ) { this.wsfe = (WSFEV1) wsfe; this.logueador = new LogueadorFe(); }
private void AplicarConfiguracionWS( SoapHttpClientProtocol ws, ConfiguracionWS config ) { ws.Url = config.UrlNegocio; ws.Timeout = config.TiempoDeEspera; if ( !config.ProxyServidor.Equals( String.Empty ) ) { WebProxy proxy = new WebProxy( config.ProxyServidor, config.ProxyPuerto ); proxy.Credentials = new NetworkCredential( config.ProxyUsuario, config.ProxyPass ); ws.Proxy = proxy; } }
public void ConfigureHttpClientProtocol(string name, SoapHttpClientProtocol httpC) { string uriString = this._url + "/" + name; httpC.Url = uriString; httpC.Credentials = this.getCredentialCache(new Uri(uriString), this._authCollection); WebProxy proxy = this.getProxy(this._proxyHost, this._proxyPort, this._authProxyCollection); if (proxy != null) { httpC.Proxy = proxy; } foreach (X509Certificate certificate in this._certificateCollection) { httpC.ClientCertificates.Add(certificate); } httpC.Timeout = this._timeout; }
private void PrepareProxy(SoapHttpClientProtocol proxy) { string smarterUrl = ServiceUrl; if (String.IsNullOrEmpty(smarterUrl)) smarterUrl = "http://localhost:9998/services/"; int idx = proxy.Url.LastIndexOf("/"); // strip the last slash if any if (smarterUrl[smarterUrl.Length - 1] == '/') smarterUrl = smarterUrl.Substring(0, smarterUrl.Length - 1); proxy.Url = smarterUrl + proxy.Url.Substring(idx); }
private WebService(SoapHttpClientProtocol svc) { _svc = svc; InitializeMethods(); }
public static System.Web.Services.Protocols.SoapHttpClientProtocol ClientProxyFactory( Parametro oParam, TServico TipoServico) { String ClassName = ""; try { string nomeClasse = string.Empty; //buscar nome do metodo pelo tServico foreach (ClasseServico atr in TipoServico.GetType().GetField(TipoServico.ToString()).GetCustomAttributes(typeof(ClasseServico), false)) { if (String.IsNullOrEmpty(atr.value)) { throw new Exception("Serviço não esta associado com nenhuma classe cliente."); } nomeClasse = atr.value; } //particularidades if (oParam.UF == TCodUfIBGE.Bahia && oParam.tipoEmissao == TNFeInfNFeIdeTpEmis.Normal)//Bahia { if (TipoServico == TServico.Status && oParam.versao == VersaoXML.NFe_v310) { nomeClasse = "NfeStatusServico"; } if (TipoServico == TServico.Consulta && oParam.versao == VersaoXML.NFe_v310) { nomeClasse = "NfeConsulta"; } if (TipoServico == TServico.Inutilizacao && oParam.versao == VersaoXML.NFe_v310) { nomeClasse = "NfeInutilizacao"; } } ClassName = "RDI.NFe2.Business." + GetAmbWebService(oParam, TipoServico) + "." + TipoServico.ToString() + "."; String headerClassName = ClassName + "nfeCabecMsg"; ClassName += nomeClasse; Type classType = GetMyAssembly().GetType(ClassName); if (classType == null) { throw new Exception("Não foi possível definir o tipo do cliente de webservice. #ClientProxyFactory"); } System.Web.Services.Protocols.SoapHttpClientProtocol oServico = (System.Web.Services.Protocols.SoapHttpClientProtocol)System.Activator.CreateInstance(classType); if (TipoServico != TServico.ConsultaDFe) //ConsultaDFe não tem header { #region Instancia cabecalho Type headerClassType = GetMyAssembly().GetType(headerClassName); if (headerClassType == null) { throw new Exception("Não foi possível definir o tipo do header do cliente de webservice. #ClientProxyFactory"); } System.Web.Services.Protocols.SoapHeader oCabecalho = (System.Web.Services.Protocols.SoapHeader)System.Activator.CreateInstance(headerClassType); if ((TipoServico == TServico.ManifestacaoDestinatario) || //ManifestacaoDestinatario deverá usar AN 91 (TipoServico == TServico.DownloadNF)) //DownloadNF deverá usar AN 91 { oCabecalho.GetType().GetProperty("cUF").SetValue(oCabecalho, "91", null); } else { oCabecalho.GetType().GetProperty("cUF").SetValue(oCabecalho, ((System.Xml.Serialization.XmlEnumAttribute)oParam.UF.GetType().GetField( oParam.UF.ToString()).GetCustomAttributes( typeof(System.Xml.Serialization.XmlEnumAttribute), false)[0]).Name, null); } string versao = oParam.versaoDados; //particularidade para ConsSitNFe usando v200 if (TipoServico == TServico.Consulta && oParam.versao == VersaoXML.NFe_v200) { versao = "2.01"; } //Particularidade para RecepcaoEvento if (TipoServico == TServico.RecepcaoEvento) { versao = oParam.versaoDadosEventos; } //particularidade para consultaCadastro if (TipoServico == TServico.Cadastro) { versao = "2.00"; } //particularidade para manifestacao destinatario if (TipoServico == TServico.ManifestacaoDestinatario || TipoServico == TServico.DownloadNF) { versao = "1.00"; } oCabecalho.GetType().GetProperty("versaoDados").SetValue(oCabecalho, versao, null); oServico.GetType().GetProperty("nfeCabecMsgValue").SetValue(oServico, oCabecalho, null); #endregion } return(oServico); } catch (Exception ex) { throw new Exception("ClientProxyFactory # não foi possível criar o cliente (" + ClassName + ") para acesso aos webservices da SEFAZ. InnerException: " + ex.Message); } }
public static System.Web.Services.Protocols.SoapHttpClientProtocol ClientProxyFactory(Parametro oParam, TService TipoServico) { if (oParam.versao == VersaoXML.NFe_v400 && (TipoServico == TService.Autorizacao || TipoServico == TService.RetAutorizacao || TipoServico == TService.ConsultaProtocolo || TipoServico == TService.Inutilizacao || TipoServico == TService.RecepcaoEvento || TipoServico == TService.Cadastro || TipoServico == TService.Status)) { if (oParam.conexao == TipoConexao.NFe) { var tServer = TServer.NaoMapeado; string Ambiente = oParam.tipoAmbiente.ToString(); var AtendidoPor = (NFe_AtendidoPor)typeof(TCodUfIBGE).GetField(oParam.UF.ToString()).GetCustomAttributes(typeof(NFe_AtendidoPor), false).FirstOrDefault(); if (AtendidoPor == null) { throw new Exception("UF não está associado com nenhum Servidor Autorizador."); } if (oParam.tipoEmissao == TNFeInfNFeIdeTpEmis.ContingenciaSVCAN || oParam.tipoEmissao == TNFeInfNFeIdeTpEmis.ContingenciaSVCRS) { tServer = AtendidoPor.ServidorAutorizadorSVC; } else { tServer = AtendidoPor.ServidorAutorizador; } return(RDI.NFe2.Webservices.WSUtils.SoapHttpClientFactory(tServer, Ambiente, TipoServico)); } else if (oParam.conexao == TipoConexao.NFCe) { var AtendidoPor = (NFCe_AtendidoPor)typeof(TCodUfIBGE).GetField(oParam.UF.ToString()).GetCustomAttributes(typeof(NFCe_AtendidoPor), false).FirstOrDefault(); if (AtendidoPor == null) { throw new Exception("UF não está associado com nenhum Servidor Autorizador."); } string Ambiente = oParam.tipoAmbiente.ToString(); return(RDI.NFe2.Webservices.WSUtils.SoapHttpClientFactory(AtendidoPor.ServidorAutorizador, Ambiente, TipoServico)); } else { throw new Exception("UF não está associado com nenhum Servidor Autorizador."); } } else { //TODO : enviar todos os webservices ativos para o projeto rdi.nfe.webservices após a desativação da versao 3.10 String ClassName = ""; try { string nomeClasse = string.Empty; //buscar nome do metodo pelo tServico foreach (ClasseServico atr in TipoServico.GetType().GetField(TipoServico.ToString()).GetCustomAttributes(typeof(ClasseServico), false)) { if (String.IsNullOrEmpty(atr.NomeClasse)) { throw new Exception("Serviço não esta associado com nenhuma classe cliente."); } nomeClasse = atr.NomeClasse; } //particularidades if (oParam.UF == TCodUfIBGE.Bahia && oParam.tipoEmissao == TNFeInfNFeIdeTpEmis.Normal && oParam.conexao == TipoConexao.NFe)//Bahia { if (TipoServico == TService.Status && oParam.versao == VersaoXML.NFe_v310) { nomeClasse = "NfeStatusServico"; } if (TipoServico == TService.ConsultaProtocolo && oParam.versao == VersaoXML.NFe_v310) { nomeClasse = "NfeConsulta"; } if (TipoServico == TService.Inutilizacao && oParam.versao == VersaoXML.NFe_v310) { nomeClasse = "NfeInutilizacao"; } } var subNamespace = TipoServico.ToString(); if (TipoServico == TService.ConsultaProtocolo) { subNamespace = "Consulta"; } else if (TipoServico == TService.ManifestacaoDestinatario || TipoServico == TService.EPEC) { subNamespace = "Eventos"; } ClassName = "RDI.NFe2.Business." + GetAmbWebService(oParam, TipoServico) + "." + subNamespace + "."; String headerClassName = ClassName + "nfeCabecMsg"; ClassName += nomeClasse; Type classType = GetMyAssembly().GetType(ClassName); if (classType == null) { throw new Exception("Não foi possível definir o tipo do cliente de webservice. #ClientProxyFactory"); } System.Web.Services.Protocols.SoapHttpClientProtocol oServico = (System.Web.Services.Protocols.SoapHttpClientProtocol)System.Activator.CreateInstance(classType); if (TipoServico != TService.ConsultaDFe) //ConsultaDFe não tem header { #region Instancia cabecalho Type headerClassType = GetMyAssembly().GetType(headerClassName); if (headerClassType == null) { throw new Exception("Não foi possível definir o tipo do header do cliente de webservice. #ClientProxyFactory"); } System.Web.Services.Protocols.SoapHeader oCabecalho = (System.Web.Services.Protocols.SoapHeader)System.Activator.CreateInstance(headerClassType); if ((TipoServico == TService.ManifestacaoDestinatario) || //ManifestacaoDestinatario deverá usar AN 91 (TipoServico == TService.DownloadNF) || //DownloadNF deverá usar AN 91 (TipoServico == TService.EPEC)) //DownloadNF deverá usar AN 91 { oCabecalho.GetType().GetProperty("cUF").SetValue(oCabecalho, "91", null); } else { oCabecalho.GetType().GetProperty("cUF").SetValue(oCabecalho, ((System.Xml.Serialization.XmlEnumAttribute)oParam.UF.GetType().GetField( oParam.UF.ToString()).GetCustomAttributes( typeof(System.Xml.Serialization.XmlEnumAttribute), false)[0]).Name, null); } string versao = oParam.versaoDados; //particularidade para ConsSitNFe usando v200 if (TipoServico == TService.ConsultaProtocolo && oParam.versao == VersaoXML.NFe_v200) { versao = "2.01"; } //Particularidade para RecepcaoEvento if (TipoServico == TService.RecepcaoEvento) { versao = oParam.versaoDadosEventos; } //particularidade para consultaCadastro if (TipoServico == TService.Cadastro) { versao = "2.00"; } //particularidade para manifestacao destinatario if (TipoServico == TService.ManifestacaoDestinatario || TipoServico == TService.EPEC || TipoServico == TService.DownloadNF) { versao = "1.00"; } oCabecalho.GetType().GetProperty("versaoDados").SetValue(oCabecalho, versao, null); oServico.GetType().GetProperty("nfeCabecMsgValue").SetValue(oServico, oCabecalho, null); #endregion } return(oServico); } catch (Exception ex) { throw new Exception("ClientProxyFactory # não foi possível criar o cliente (" + ClassName + ") para acesso aos webservices da SEFAZ. InnerException: " + ex.Message); } } }
private SoapClientMessage BeforeSerialize(WebRequest request, string methodName, object[] parameters) { if (parameters == null) { throw new ArgumentNullException("parameters"); } SoapClientMethod method = this.clientType.GetMethod(methodName); if (method == null) { throw new ArgumentException(System.Web.Services.Res.GetString("WebInvalidMethodName", new object[1] { (object)methodName })); } else { SoapExtension[] soapExtensionArray = SoapMessage.InitializeExtensions((SoapReflectedExtension[])SoapHttpClientProtocol.CombineExtensionsHelper((Array)this.clientType.HighPriExtensions, (Array)method.extensions, (Array)this.clientType.LowPriExtensions, typeof(SoapReflectedExtension)), (object[])SoapHttpClientProtocol.CombineExtensionsHelper((Array)this.clientType.HighPriExtensionInitializers, (Array)method.extensionInitializers, (Array)this.clientType.LowPriExtensionInitializers, typeof(object))); SoapClientMessage soapClientMessage = new SoapClientMessage(this, method, this.Url); soapClientMessage.initializedExtensions = soapExtensionArray; if (soapExtensionArray != null) { soapClientMessage.SetExtensionStream(new SoapExtensionStream()); } soapClientMessage.InitExtensionStreamChain(soapClientMessage.initializedExtensions); string action = UrlEncoder.EscapeString(method.action, Encoding.UTF8); soapClientMessage.SetStage(SoapMessageStage.BeforeSerialize); if (this.version == SoapProtocolVersion.Soap12) { soapClientMessage.ContentType = ContentType.Compose("application/soap+xml", this.RequestEncoding != null ? this.RequestEncoding : Encoding.UTF8, action); } else { soapClientMessage.ContentType = ContentType.Compose("text/xml", this.RequestEncoding != null ? this.RequestEncoding : Encoding.UTF8); } soapClientMessage.SetParameterValues(parameters); SoapHeaderHandling.GetHeaderMembers(soapClientMessage.Headers, (object)this, method.inHeaderMappings, SoapHeaderDirection.In, true); soapClientMessage.RunExtensions(soapClientMessage.initializedExtensions, true); request.ContentType = soapClientMessage.ContentType; if (soapClientMessage.ContentEncoding != null && soapClientMessage.ContentEncoding.Length > 0) { ((NameValueCollection)request.Headers)["Content-Encoding"] = soapClientMessage.ContentEncoding; } request.Method = "POST"; if (this.version != SoapProtocolVersion.Soap12 && ((NameValueCollection)request.Headers)["SOAPAction"] == null) { StringBuilder stringBuilder = new StringBuilder(action.Length + 2); stringBuilder.Append('"'); stringBuilder.Append(action); stringBuilder.Append('"'); ((NameValueCollection)request.Headers).Add("SOAPAction", ((object)stringBuilder).ToString()); } return(soapClientMessage); } }
public ServidorFacturaElectronicaMTXCA( SoapHttpClientProtocol wsfe, LogueadorFe logueador ) { this.wsfe = (WSMTXCA) wsfe; this.logueador = logueador; }
private static String ExecutaServico( System.Web.Services.Protocols.SoapHttpClientProtocol oServico, Object DADOS, Parametro oParam) { try { string dados = XMLUtils.GetXML(DADOS, oParam.versao); #region particularidades if (oParam.UF == TCodUfIBGE.Parana && (DADOS.GetType() == typeof(SchemaXML200.TEnviNFe) || DADOS.GetType() == typeof(SchemaXML300.TEnviNFe) || DADOS.GetType() == typeof(SchemaXML310.TEnviNFe))) { dados = dados.Replace("<NFe>", "<NFe xmlns=\"http://www.portalfiscal.inf.br/nfe\">"); } #endregion XmlNode node = null; XmlDocument doc = new XmlDocument(); XmlReader reader = XmlReader.Create(new StringReader(dados)); reader.MoveToContent(); node = doc.ReadNode(reader); InicializaServico(oServico, oParam); if (DADOS.GetType() == typeof(RDI.NFe2.GNRE.TLote_GNRE)) { XmlNode ret = (XmlNode)oServico.GetType().InvokeMember("processar", System.Reflection.BindingFlags.InvokeMethod, null, oServico, new object[] { node }); return(XMLUtils.GetXML(ret, oParam.versao)); } else if (DADOS.GetType() == typeof(RDI.NFe2.GNRE.TConsLote_GNRE)) { XmlNode ret = (XmlNode)oServico.GetType().InvokeMember("consultar", System.Reflection.BindingFlags.InvokeMethod, null, oServico, new object[] { node }); return(XMLUtils.GetXML(ret, oParam.versao)); } else if (DADOS.GetType() == typeof(RDI.NFe2.GNRE.TConsultaConfigUf)) { XmlNode ret = (XmlNode)oServico.GetType().InvokeMember("consultar", System.Reflection.BindingFlags.InvokeMethod, null, oServico, new object[] { node }); return(XMLUtils.GetXML(ret, oParam.versao)); } else if (DADOS.GetType().GetInterface("ITConsCad") != null) { XmlNode ret = (XmlNode)oServico.GetType().InvokeMember("consultaCadastro2", System.Reflection.BindingFlags.InvokeMethod, null, oServico, new object[] { node }); return(XMLUtils.GetXML(ret, oParam.versao)); } else if (DADOS.GetType().GetInterface("ITEnvEvento") != null) { XmlNode ret = (XmlNode)oServico.GetType().InvokeMember("nfeRecepcaoEvento", System.Reflection.BindingFlags.InvokeMethod, null, oServico, new object[] { node }); return(XMLUtils.GetXML(ret, oParam.versao)); } else if (DADOS.GetType().GetInterface("ITEnviNFe") != null) { if (((ITEnviNFe)DADOS).versao == "2.00") { //versao 2.00 #region particularidades if (oParam.UF == TCodUfIBGE.Parana) { if (oParam.tipoAmbiente == TAmb.Homologacao) { oServico.Url = @"https://homologacao.nfe2.fazenda.pr.gov.br/nfe/NFeRecepcao2"; } else { oServico.Url = @"https://nfe2.fazenda.pr.gov.br/nfe/NFeRecepcao2"; } } #endregion XmlNode ret = (XmlNode)oServico.GetType().InvokeMember("nfeRecepcaoLote2", System.Reflection.BindingFlags.InvokeMethod, null, oServico, new object[] { node }); return(XMLUtils.GetXML(ret, oParam.versao)); } else { //versao 3.00 //Somente meto Assincrono //var test = (SchemaXML300.TEnviNFe)DADOS; //test.indSinc = SchemaXML300.TEnviNFeIndSinc.Item0;//Não indica sincrono //test.indSinc = SchemaXML300.TEnviNFeIndSinc.Item1; //indica sincrono, mas depende da SEFAZ autorizadora implementar servico. //***.**.Autorizacao.NfeAutorizacao proxy = new ***.**.Autorizacao.NfeAutorizacao(); //var ret = proxy.nfeAutorizacaoLote(node); //sincrono poderá ter o Nó : TProtNFe //assincrono terá o Nó : TRetEnviNFeInfRec var fnNome = "nfeAutorizacaoLote"; XmlNode ret = (XmlNode)oServico.GetType().InvokeMember(fnNome, System.Reflection.BindingFlags.InvokeMethod, null, oServico, new object[] { node }); return(XMLUtils.GetXML(ret, oParam.versao)); } } else if (DADOS.GetType().GetInterface("ITConsReciNFe") != null) { if (((ITConsReciNFe)DADOS).versao == "2.00") { //versao 2.00 #region particularidades if (oParam.UF == TCodUfIBGE.Parana) { if (oParam.tipoAmbiente == TAmb.Homologacao) { oServico.Url = @"https://homologacao.nfe2.fazenda.pr.gov.br/nfe/NFeRetRecepcao2"; } else { oServico.Url = @"https://nfe2.fazenda.pr.gov.br/nfe/NFeRetRecepcao2"; } } #endregion XmlNode ret = (XmlNode)oServico.GetType().InvokeMember("nfeRetRecepcao2", System.Reflection.BindingFlags.InvokeMethod, null, oServico, new object[] { node }); return(XMLUtils.GetXML(ret, oParam.versao)); } else { var fnNome = "nfeRetAutorizacaoLote"; if (oParam.UF == TCodUfIBGE.Parana && oParam.versao == VersaoXML.NFe_v310) { fnNome = "nfeRetAutorizacao"; } //versao 3.00 ou 3.10 XmlNode ret = (XmlNode)oServico.GetType().InvokeMember(fnNome, System.Reflection.BindingFlags.InvokeMethod, null, oServico, new object[] { node }); var temp = XMLUtils.GetXML(ret, oParam.versao); if (oParam.UF == TCodUfIBGE.Pernambuco) { //SEFAZ PE está retornando retEnviNFe ao inves de retConsReciNFe quando lote ainda está em processamento temp = temp.Replace("retEnviNFe", "retConsReciNFe"); } return(temp); } } else if (DADOS.GetType().GetInterface("ITConsStatServ") != null) { var fnNome = "nfeStatusServicoNF2"; if ((oParam.UF == TCodUfIBGE.Parana || oParam.UF == TCodUfIBGE.Bahia) && oParam.tipoEmissao == TNFeInfNFeIdeTpEmis.Normal && oParam.versao == VersaoXML.NFe_v310) { fnNome = "nfeStatusServicoNF"; } XmlNode ret = (XmlNode)oServico.GetType().InvokeMember(fnNome, System.Reflection.BindingFlags.InvokeMethod, null, oServico, new object[] { node }); return(XMLUtils.GetXML(ret, oParam.versao)); } else if (DADOS.GetType().GetInterface("ITInutNFe") != null) { var fnNome = "nfeInutilizacaoNF2"; if ((oParam.UF == TCodUfIBGE.Parana || oParam.UF == TCodUfIBGE.Bahia) && oParam.tipoEmissao == TNFeInfNFeIdeTpEmis.Normal && oParam.versao == VersaoXML.NFe_v310) { fnNome = "nfeInutilizacaoNF"; } XmlNode ret = (XmlNode)oServico.GetType().InvokeMember(fnNome, System.Reflection.BindingFlags.InvokeMethod, null, oServico, new object[] { node }); return(XMLUtils.GetXML(ret, oParam.versao)); } else if (DADOS.GetType().GetInterface("ITConsSitNFe") != null) { string fnNome = "nfeConsultaNF2"; if ((oParam.UF == TCodUfIBGE.Parana || oParam.UF == TCodUfIBGE.Bahia) && oParam.tipoEmissao == TNFeInfNFeIdeTpEmis.Normal && oParam.versao == VersaoXML.NFe_v310) { fnNome = "nfeConsultaNF"; } XmlNode ret = (XmlNode)oServico.GetType().InvokeMember(fnNome, System.Reflection.BindingFlags.InvokeMethod, null, oServico, new object[] { node }); return(XMLUtils.GetXML(ret, oParam.versao)); } else if (DADOS.GetType().GetInterface("IDistDFeInt") != null) { XmlNode ret = (XmlNode)oServico.GetType().InvokeMember("nfeDistDFeInteresse", System.Reflection.BindingFlags.InvokeMethod, null, oServico, new object[] { node }); return(XMLUtils.GetXML(ret, oParam.versao)); } else if (DADOS.GetType().GetInterface("ITDownloadNFe") != null) { XmlNode ret = (XmlNode)oServico.GetType().InvokeMember("nfeDownloadNF", System.Reflection.BindingFlags.InvokeMethod, null, oServico, new object[] { node }); return(XMLUtils.GetXML(ret, oParam.versao)); } else { throw new Exception("Tipo de objeto de envio não mapeado. Consulte o administrador do Sistema."); } } catch (Exception ex) { String msg = ex.Message; if (ex.InnerException != null) { msg += " inner : " + ex.InnerException.Message; } if (ex.InnerException.InnerException != null) { msg += " inner : " + ex.InnerException.InnerException.Message; } throw new Exception("Erro ao executar Serviço : typeof(" + DADOS.GetType().ToString() + "). Verifique sua conexão com a Internet, configurações de proxy e certificado. " + msg); } }