0
I am trying to communicate my application with the Cadsus web service from an Asp . net core application. I have using the code below, but whenever I try to recover the return of the query I get the error "The HTTP request was Forbidden with client Authentication Scheme 'Anonymous'".
var address = new EndpointAddress("https://servicos.saude.gov.br/cadsus/v5r0/cadsusservice");
BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
var cad = new CadsusServicePortTypeClient(CadsusServicePortTypeClient.EndpointConfiguration.CadsusServicePort, address);//binding, address
cad.ClientCredentials.UserName.UserName = "-----------------------------";
cad.ClientCredentials.UserName.Password = "---------------------";
cad.ClientCredentials.ClientCertificate.SetCertificate(StoreLocation.LocalMachine,
StoreName.My,
X509FindType.FindBySubjectName, "");
requestPesquisar itenspesquisa = new requestPesquisar();
itenspesquisa.CNESUsuario = new CNESUsuarioType()
{
CNES = "*",
Usuario = "*"
};
itenspesquisa.FiltroPesquisa = new FiltroPesquisa()
{
nomeCompleto = new NomeCompletoType { Nome = "*" },
dataNascimentoSpecified = false,
CPF = new CPFType { numeroCPF = "*" },
tipoPesquisa = TipoPesquisaType.APROXIMADA
};
itenspesquisa.higienizar = false;
ResultadoPesquisa[] resultWS = cad.pesquisarAsync(itenspesquisa).Result.responsePesquisar1;
foreach (ResultadoPesquisa result in resultWS)
{
var teste = result.CNS;
}
Any idea what it might be?