I am developing a project that will send XMLs to the WS of the federal revenue, I made the reference using the following URL: link
But when you go through the Test Role EnvioRPS()
you get the following error:
"The HTTP request is prohibited with the client authentication scheme 'Anonymous'"
To test WS I'm doing the following in a Button_Click event:
Dim WS As New WebServiceNFSE_TESTE.LoteNFeSoapClient
Dim Busca As X509Certificate2 = Buscar_Certificado_Nome("")
'Teste
MessageBox.Show(WS.EnvioRPS(1, ""))
Role searching for certificate:
Public Shared Function Buscar_Certificado_Nome(_nm_certificado As String) As X509Certificate2
Dim X509_certificado As New X509Certificate2()
Dim X509_store As New X509Store("MY", StoreLocation.CurrentUser)
X509_store.Open(OpenFlags.[ReadOnly] Or OpenFlags.OpenExistingOnly Or OpenFlags.IncludeArchived)
Dim X509_collection0 As X509Certificate2Collection = DirectCast(X509_store.Certificates, X509Certificate2Collection)
Dim X509_collection1 As X509Certificate2Collection = DirectCast(X509_collection0.Find(X509FindType.FindByTimeValid, DateTime.Now, False), X509Certificate2Collection)
Dim X509_collection2 As X509Certificate2Collection = DirectCast(X509_collection0.Find(X509FindType.FindByKeyUsage, X509KeyUsageFlags.DigitalSignature, False), X509Certificate2Collection)
If _nm_certificado = "" Then
Dim scollection As X509Certificate2Collection = X509Certificate2UI.SelectFromCollection(X509_collection2, "Certificado(s) Digital(is) disponível(is)", "Selecione o Certificado Digital para uso no aplicativo", X509SelectionFlag.SingleSelection)
If scollection.Count = 0 Then
'Nenhum certificado escolhido
X509_certificado.Reset()
Else
X509_certificado = scollection(0)
End If
Else
Dim scollection As X509Certificate2Collection = X509_collection1.Find(X509FindType.FindByThumbprint, "ce c9 ed 7a b6 54 fe fe 1b bf 31 78 ef 5f 74 be be 6e e8 12", True)
If scollection.Count = 0 Then
'Nenhum certificado válido foi encontrado com o nome informado
X509_certificado.Reset()
Else
X509_certificado = scollection(0)
End If
End If
X509_store.Close()
Return X509_certificado
End Function