5
I came across this method in a code and was curious how it works because I’ve seen some applications running in C# that use this method, and when searching for the method in Google, I found no clear explanation.
tipoServico.InvokeMember("SalvarXmlRetornoEm", System.Reflection.BindingFlags.SetProperty, null, xml, new object[] { repositorio.xmlRetorno });
This is an example of a code that I saw that it works all right but I have no idea how it works.
private void EnviarArquivo(Empresa empresa, string arquivoXmlEnvio, string localSalvarXmlRetorno, Object nfe, string metodo)
{
//Definir o tipo do serviço
Type tipoServico = nfe.GetType();
//Definir o arquivo XML para a classe UniNfeClass
tipoServico.InvokeMember("NomeArquivoXML", System.Reflection.BindingFlags.SetProperty, null, nfe, new object[] { arquivoXmlEnvio });
tipoServico.InvokeMember("SalvarXmlRetornoEm", System.Reflection.BindingFlags.SetProperty, null, nfe, new object[] { localSalvarXmlRetorno });
tipoServico.InvokeMember(metodo, System.Reflection.BindingFlags.InvokeMethod, null, nfe, new[] { empresa });
}
So the Nfe object is this one:
public class TaskConsultarNfsePorRps : TaskAbst
{
public override void Execute(Empresa empresa)
{
//Definir o serviço que será executado para a classe
Servico = Servicos.ConsultarNfsePorRps;
//Ler o XML para pegar parâmetros de envio
LerXML ler = new LerXML();
ler.PedSitNfseRps(NomeArquivoXML, empresa);
//Criar objetos das classes dos serviços dos webservices do SEFAZ
WebServiceProxy wsProxy = null;
object pedLoteRps = null;
string cabecMsg = "";
PadroesNFSe padraoNFSe = Functions.PadraoNFSe(ler.oDadosPedSitNfseRps.cMunicipio);
switch (padraoNFSe)
{
case PadroesNFSe.GINFES:
wsProxy = ConfiguracaoApp.DefinirWS(Servico, empresa, ler.oDadosPedSitNfseRps.cMunicipio, ler.oDadosPedSitNfseRps.tpAmb, ler.oDadosPedSitNfseRps.tpEmis);
pedLoteRps = wsProxy.CriarObjeto(NomeClasseWS(Servico, ler.oDadosPedSitNfseRps.cMunicipio));
cabecMsg = "<ns2:cabecalho versao=\"3\" xmlns:ns2=\"http://www.ginfes.com.br/cabecalho_v03.xsd\"><versaoDados>3</versaoDados></ns2:cabecalho>";
break;
case PadroesNFSe.BETHA:
wsProxy = new WebServiceProxy(empresa.X509Certificado);
wsProxy.Betha = new Betha();
break;
case PadroesNFSe.THEMA:
wsProxy = ConfiguracaoApp.DefinirWS(Servico, empresa, ler.oDadosPedSitNfseRps.cMunicipio, ler.oDadosPedSitNfseRps.tpAmb, ler.oDadosPedSitNfseRps.tpEmis);
pedLoteRps = wsProxy.CriarObjeto(NomeClasseWS(Servico, ler.oDadosPedSitNfseRps.cMunicipio));
break;
case PadroesNFSe.CANOAS_RS:
wsProxy = ConfiguracaoApp.DefinirWS(Servico, empresa, ler.oDadosPedSitNfseRps.cMunicipio, ler.oDadosPedSitNfseRps.tpAmb, ler.oDadosPedSitNfseRps.tpEmis);
pedLoteRps = wsProxy.CriarObjeto(NomeClasseWS(Servico, ler.oDadosPedSitNfseRps.cMunicipio));
cabecMsg = "<cabecalho versao=\"201001\"><versaoDados>V2010</versaoDados></cabecalho>";
break;
case PadroesNFSe.ISSNET:
wsProxy = ConfiguracaoApp.DefinirWS(Servico, empresa, ler.oDadosPedSitNfseRps.cMunicipio, ler.oDadosPedSitNfseRps.tpAmb, ler.oDadosPedSitNfseRps.tpEmis);
pedLoteRps = wsProxy.CriarObjeto(NomeClasseWS(Servico, ler.oDadosPedSitNfseRps.cMunicipio));
break;
case PadroesNFSe.ISSONLINE:
wsProxy = ConfiguracaoApp.DefinirWS(Servico, empresa, ler.oDadosPedSitNfseRps.cMunicipio, ler.oDadosPedSitNfseRps.tpAmb, ler.oDadosPedSitNfseRps.tpEmis);
pedLoteRps = wsProxy.CriarObjeto(NomeClasseWS(Servico, ler.oDadosPedSitNfseRps.cMunicipio));
break;
case PadroesNFSe.BLUMENAU_SC:
wsProxy = ConfiguracaoApp.DefinirWS(Servico, empresa, ler.oDadosPedSitNfseRps.cMunicipio, ler.oDadosPedSitNfseRps.tpAmb, ler.oDadosPedSitNfseRps.tpEmis);
pedLoteRps = wsProxy.CriarObjeto(NomeClasseWS(Servico, ler.oDadosPedSitNfseRps.cMunicipio));
break;
case PadroesNFSe.BHISS:
wsProxy = ConfiguracaoApp.DefinirWS(Servico, empresa, ler.oDadosPedSitNfseRps.cMunicipio, ler.oDadosPedSitNfseRps.tpAmb, ler.oDadosPedSitNfseRps.tpEmis);
pedLoteRps = wsProxy.CriarObjeto(NomeClasseWS(Servico, ler.oDadosPedSitNfseRps.cMunicipio));
cabecMsg = "<cabecalho xmlns=\"http://www.abrasf.org.br/nfse.xsd\" versao=\"1.00\"><versaoDados >1.00</versaoDados ></cabecalho>";
break;
case PadroesNFSe.GIF:
wsProxy = ConfiguracaoApp.DefinirWS(Servico, empresa, ler.oDadosPedSitNfseRps.cMunicipio, ler.oDadosPedSitNfseRps.tpAmb, ler.oDadosPedSitNfseRps.tpEmis);
pedLoteRps = wsProxy.CriarObjeto(NomeClasseWS(Servico, ler.oDadosPedSitNfseRps.cMunicipio));
break;
case PadroesNFSe.DUETO:
wsProxy = ConfiguracaoApp.DefinirWS(Servico, empresa, ler.oDadosPedSitNfseRps.cMunicipio, ler.oDadosPedSitNfseRps.tpAmb, ler.oDadosPedSitNfseRps.tpEmis, padraoNFSe);
pedLoteRps = wsProxy.CriarObjeto(NomeClasseWS(Servico, ler.oDadosPedSitNfseRps.cMunicipio));
break;
case PadroesNFSe.WEBISS:
wsProxy = ConfiguracaoApp.DefinirWS(Servico, empresa, ler.oDadosPedSitNfseRps.cMunicipio, ler.oDadosPedSitNfseRps.tpAmb, ler.oDadosPedSitNfseRps.tpEmis, padraoNFSe);
pedLoteRps = wsProxy.CriarObjeto(NomeClasseWS(Servico, ler.oDadosPedSitNfseRps.cMunicipio));
cabecMsg = "<cabecalho xmlns=\"http://www.abrasf.org.br/nfse.xsd\" versao=\"1.00\"><versaoDados >1.00</versaoDados ></cabecalho>";
break;
case PadroesNFSe.PAULISTANA:
wsProxy = ConfiguracaoApp.DefinirWS(Servico, empresa, ler.oDadosPedSitNfseRps.cMunicipio, ler.oDadosPedSitNfseRps.tpAmb, ler.oDadosPedSitNfseRps.tpEmis);
pedLoteRps = wsProxy.CriarObjeto(NomeClasseWS(Servico, ler.oDadosPedSitNfseRps.cMunicipio));
break;
case PadroesNFSe.SALVADOR_BA:
wsProxy = ConfiguracaoApp.DefinirWS(Servico, empresa, ler.oDadosPedSitNfseRps.cMunicipio, ler.oDadosPedSitNfseRps.tpAmb, ler.oDadosPedSitNfseRps.tpEmis, padraoNFSe);
pedLoteRps = wsProxy.CriarObjeto(NomeClasseWS(Servico, ler.oDadosPedSitNfseRps.cMunicipio));
break;
case PadroesNFSe.PORTOVELHENSE:
wsProxy = ConfiguracaoApp.DefinirWS(Servico, empresa, ler.oDadosPedSitNfseRps.cMunicipio, ler.oDadosPedSitNfseRps.tpAmb, ler.oDadosPedSitNfseRps.tpEmis, padraoNFSe);
pedLoteRps = wsProxy.CriarObjeto(NomeClasseWS(Servico, ler.oDadosPedSitNfseRps.cMunicipio));
cabecMsg = "<cabecalho versao=\"2.00\" xmlns:ns2=\"http://www.w3.org/2000/09/xmldsig#\" xmlns=\"http://www.abrasf.org.br/nfse.xsd\"><versaoDados>2.00</versaoDados></cabecalho>";
break;
case PadroesNFSe.PRONIN:
wsProxy = ConfiguracaoApp.DefinirWS(Servico, empresa, ler.oDadosPedSitNfseRps.cMunicipio, ler.oDadosPedSitNfseRps.tpAmb, ler.oDadosPedSitNfseRps.tpEmis, padraoNFSe);
pedLoteRps = wsProxy.CriarObjeto(NomeClasseWS(Servico, ler.oDadosPedSitNfseRps.cMunicipio));
break;
default:
throw new Exception("Não foi possível detectar o padrão da NFS-e.");
}
if (padraoNFSe != PadroesNFSe.IPM)
{
//Assinar o XML
AssinaturaDigital ad = new AssinaturaDigital();
ad.Assinar(NomeArquivoXML, empresa, Convert.ToInt32(ler.oDadosPedSitNfseRps.cMunicipio));
//Invocar o método que envia o XML para o SEFAZ
oInvocarObj.InvocarNFSe(wsProxy, pedLoteRps, NomeMetodoWS(Servico, ler.oDadosPedSitNfseRps.cMunicipio, empresa.tpAmb), cabecMsg, this, "-ped-sitnfserps", "-sitnfserps", padraoNFSe, Servico, empresa);
}
}
}
It would help if the question were clear on what you want to know, what you want to do with it. You could quote where you saw it, what you didn’t understand, post an example of use you can’t use, if you want to make it work internally, or something else. The documentation is here: https://msdn.microsoft.com/en-us/library/66btctbe(v=vs.110). aspx.
– Maniero
is that actually I wanted to know exactly this, where I can use this method, I read this documentation and it was not so clear to me, so I would like to learn where I can apply it, what it is useful and helps...
– Brayan
It’s just hard to talk about something so abstractly, without a focus. This is used for reflection https://answall.com/q/13089/101. If you do not need reflection, you do not need this method. If you want to see an example of use: https://answall.com/q/137542/101. It’s complicated? It is. That’s why you need to let us know what you want.
– Maniero
This example has already helped, but even if we know more details about what comes in
nfe
can answer better. I have a larger impression that this code is the gambit of someone who does not know what they are doing. But I can only state in more detail what this method is called. Apparently more people do not know well about it since I took negative. I ended up negatively the response of the gypsy because she is wrong, just read my answer to see the constant mistakes there. He even ended up erasing his, pity that did not withdraw the negative of my reply.– Maniero
I added what’s in the question
– Brayan
I improved the answer with what you just added. I was really right, you don’t need this whole complication.
– Maniero