构建客户端应用程序以使用受证书保护的 WCF。Cert 已安装并可通过 IE 访问 WSDL,但应用程序在遇到 CaseExists 时会抛出“FaultException `1 was unhanded: Invalid Certificate”。有任何想法吗?如果证书无效,在 IE 中点击 WSDL 时会不会出错?
using System;
using System.Configuration;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Security;
using System.Security.Cryptography.X509Certificates;
using System.ServiceModel.Description;
using ConsoleApplication1.ServiceReference1;
using System.Diagnostics;
using System.ServiceModel.Channels;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
// binding
BasicHttpBinding b = new BasicHttpBinding();
b.Security.Mode = BasicHttpSecurityMode.Transport;
b.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
// endpoint
EndpointAddress ea = new EndpointAddress(
"https://cut out endpoint.svc");
// fire it up
EBondingClient client = new EBondingClient(b, ea);
// toss in cert
client.ClientCredentials.Peer.PeerAuthentication.CertificateValidationMode =
System.ServiceModel.Security.X509CertificateValidationMode.None;
client.ClientCredentials.ClientCertificate.SetCertificate(
StoreLocation.CurrentUser,
StoreName.My,
X509FindType.FindBySubjectName,
"cut.out.cert.name");
// call
Console.WriteLine(client.CaseExists("hello world"));
client.Close();
Console.ReadLine();
}
}
}