WCF custombinding与客户端证书
问题描述:
我想创建一个customBinding
调用带有SOAP 1.2,TLS和客户端证书的Web服务。因为我不能忍受,所以这只适用于customBinding
。WCF custombinding与客户端证书
我已经定义了以下行为:
<behaviors>
<endpointBehaviors>
<behavior name="TehRightBehaviour">
<clientCredentials>
<serviceCertificate>
<defaultCertificate findValue="WebInterface" x509FindType="FindBySubjectName" />
<authentication revocationMode="NoCheck" certificateValidationMode="None" />
</serviceCertificate>
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
客户确实发现该证书,如果我指定一个错误的名字,它会引发和错误。我绑定的样子:
<customBinding>
<binding name="TehRealBinding">
<transactionFlow />
<textMessageEncoding messageVersion="Soap12" />
<security authenticationMode="MutualCertificate" />
<httpsTransport requireClientCertificate="true" />
</binding>
</customBinding>
我在终点喜欢结合起来:
<client>
<endpoint address="https://hestia1:8081/cm/main"
behaviorConfiguration="TehRightBehaviour"
binding="customBinding"
bindingConfiguration="TehRealBinding"
contract="BrightMain.CMMainService"
name="cmmain" />
</client>
的问题是,如果我调用Web服务时,它抛出一个异常说
“”未提供客户端证书,请在ClientCredentials中指定客户端证书。“
我发现有几点要指定证书,显然我使用的是错误的。所以我的问题是:哪个是正确的?
由于提前, 克里斯托夫
编辑:或许,我应该学会阅读,因为指定<serviceCertificate>
是obivously不suffictient。我现在会检查这个...
答
我应该是这个样子
<behavior name="TehRightBehaviour">
<clientCredentials>
<!-- clientCertificate not defaultCertificate -->
<clientCertificate findValue="WebInterface" x509FindType="FindBySubjectName" />
<serviceCertificate>
<authentication revocationMode="NoCheck" certificateValidationMode="None" />
</serviceCertificate>
</clientCredentials>
</behavior>
答
我安装的证书在“个人”,并使用下面的代码,它为我工作。
X509Store keystore = new X509Store(StoreName.My, StoreLocation.CurrentUser);
keystore.Open(OpenFlags.ReadOnly);
var certificates = keystore.Certificates;
foreach (var certificate in certificates)
{
var friendlyName = certificate.FriendlyName;
var xname = certificate.GetName();
}
X509Certificate certificatex = certificates[0];
X509Certificate2Collection certs = keystore.Certificates.Find(X509FindType.
FindBySubjectName, "Name of subject", false);
,然后你将通过它在您的客户端请求
xyzClient.ClientCredentials.ClientCertificate.Certificate = certs[0];
我发现自己在此期间,太。另外:至少在我的情况下,标签中的也是必需的。 –
Christoph
2012-04-20 09:40:31