2
I am developing a project that will send Xmls to the WS of the IRS, I made the reference using the following URL: https://nfe.prefeitura.sp.gov.br/ws/lotenfe.asmx
But when it passes the Test Function EnvioRPS()
of the following error:
"The HTTP request is prohibited with the client authentication scheme 'Anonymous'"
To make a test with WS I am 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, ""))
Function seeking the 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