Estoy tratando de obtener el servidor WCF y el cliente se autentican mutuamente utilizando certificados SSL en el nivel de transporte utilizando BasicHttpBinding. Así es como se está creado el servidor:BasicHttpBinding con autenticación de certificado: ¿error "prohibido"?
var soapBinding = new BasicHttpBinding() { Namespace = "http://test.com" };
soapBinding.Security.Mode = BasicHttpSecurityMode.Transport;
soapBinding.Security.Transport.ClientCredentialType =
HttpClientCredentialType.Certificate;
var sh = new ServiceHost(typeof(Service1), uri);
sh.AddServiceEndpoint(typeof(IService1), soapBinding, "");
sh.Credentials.ServiceCertificate.SetCertificate(
StoreLocation.LocalMachine, StoreName.My,
X509FindType.FindBySubjectName, "localhost");
sh.Open();
aquí es el cliente:
var binding = new BasicHttpBinding();
binding.Security.Mode = BasicHttpSecurityMode.Transport;
var service = new ServiceReference2.Service1Client(binding,
new EndpointAddress("https://localhost:801/Service1"));
service.ClientCredentials.ClientCertificate.SetCertificate(
StoreLocation.LocalMachine, StoreName.My,
X509FindType.FindBySubjectName, "localhost");
service.ClientCredentials.ServiceCertificate.Authentication.
CertificateValidationMode =
System.ServiceModel.Security.X509CertificateValidationMode.PeerTrust;
service.HelloWorld();
Certificado para localhost está en Personal, raíz de confianza y contenedores tercera parte de confianza. Internet Explorer puede conectarse al host y ver WSDL. Además, las llamadas SSL funcionan bien con ClientCredentialType = HttpClientCredentialType.None
HelloWorld() falla con:
System.ServiceModel.Security.MessageSecurityException occurred<br/>
Message="The HTTP request was forbidden with client authentication
scheme 'Anonymous'."
que es una excepción relanza de: "El servidor remoto devolvió un error: (403) Prohibida."
¿cómo se puede saber que está sucediendo wtf?
No puedo creer que era tan fácil y yo no cogerlo :( – galets
Tengo el mismo problema, pero en el que el app.config tiene: en el elemento de transporte :-( –
Ronnie
Estoy tratando de resolver un problema similar - Acabo de probar su código, pero "agregar referencia de servicio" no funcionó en el cliente . Supongo que no podría adjuntar toda su solución? – user1229458