2
I have a variable that I return that is of the type x509Certificate2
, But once you get back into the system, it always comes null, but from the webserver, it returns perfectly, I’m not sure how to convert.
I created a class
with the same name, and the same variable, and I do so:
ResultadoCert a = new ResultadoCert();
a.Certificado = (await client.CertificadoAsync(item.Serial));
It returns the following error:
Cannot convert type implicitly "Servicereference1.Resultadocert" in "System.Security.Cryptography.X509certificates.X509certificate2"
How can I fix it? I have tried to collect on var, and pass to x509Certificate2
but he comes null
EDIT
That’s the class
to receive, I changed a little now:
public class ResultadoCert {
[IgnoreDataMember]
public X509Certificate2 Certificado { get; set; }
}
And here’s what I return from webservice
public ResultadoCert Certificado(string serial)
{
ResultadoCert resultado = new ResultadoCert();
X509Certificate2Collection collection = Certificados.SelecionarCertificado(serial);
if (collection.Count == 1)
{
resultado.Certificado = collection[0];
resultado.Result = true;
return resultado;
}
else { resultado.Result = false; resultado.Certificado = null; return resultado; }
}
Here’s how I’m trying to get paid:
ResultadoCert a = new ResultadoCert();
var cert = await client.CertificadoAsync(item.Serial);
if (cert.Result)
{
a.Certificado = cert.Certificado;
//a.Certificado = client.CertificadoAsync(item.Serial).Result.Certificado;
}
Debugging in webservice, it returns correctly, but when I pass the feedback I’m having problems.
i don’t know how your code is, but could you check two things ? 1º - Make sure you’re on Client Right, I imagine you’ve done it a thousand times, but just to confirm. 2º - Make sure the return of your method is a Task<x509Certificate2>, for methods Async We need to put this in the return so that it can come properly. If you can show all the code to us, your method, your class, the type, and especially the return, it would help the community a lot to help you.
– Richard Willian
@Richardwillian edited the question.
– Mariana