I am trying to perform the service status query for NFe 3.10 but is always returning the following message:
The HTTP request is prohibited with the authentication scheme of customer 'Anonymous'.
I'm using Visual Studio 2012 and .NET Framework 4.5.
I'm using the code below, could anyone tell me if something is missing?
String caminho = "C:\Arquivos\Upload\certificado.pfx";
String senha = "123456789";
X509Certificate2 certificado = new X509Certificate2(caminho, senha);
TConsStatServ statusServer = new TConsStatServ();
statusServer.versao = "3.10";
statusServer.tpAmb = TAmb.Item2;
statusServer.cUF = TCodUfIBGE.Item42;
statusServer.xServ = TConsStatServXServ.STATUS;
XmlDocument doc = ObjectToXMLDocument(statusServer);
nfeCabecMsg nfeCabecalho = new nfeCabecMsg();
nfeCabecalho.cUF = "42";
nfeCabecalho.versaoDados = "3.10";
NfeStatusServico2Soap12Client statusServicoClient = new NfeStatusServico2Soap12Client();
System.ServiceModel.EndpointAddress endereco = new System.ServiceModel.EndpointAddress("https://homologacao.nfe.sefaz.rs.gov.br/ws/NfeStatusServico/NfeStatusServico2.asmx");
statusServicoClient.Endpoint.Address = endereco;
statusServicoClient.ClientCredentials.ClientCertificate.Certificate = certificado;
var retorno = statusServicoClient.nfeStatusServicoNF2(ref nfeCabecalho, doc);
Through the browser it asks me for the certificate and I can access WS. I've tried to use the calls:
X509Certificate2 certificado = new X509Certificate2(caminho, senha, X509KeyStorageFlags.MachineKeySet);
System.ServiceModel.EndpointAddress endereco = new System.ServiceModel.EndpointAddress("https://homologacao.nfe.sefaz.rs.gov.br/ws/NfeStatusServico/NfeStatusServico2.asmx?WSDL");