2009-02-19 55 views
2

我在WCF中有一个自定义的ClientCredentials实现。 ClientCredentials的两个基本属性是ClientCertificate和ServiceCertificate,如here (MSDN)所示。未在自定义凭据上设置WCF证书

在我的配置,我有我的自定义设置ClientCredentials,和两个证书定义:

 <endpointBehaviors> 
      <behavior name="MyCustomEndpointBehavior"> 
       <clientCredentials type="MyApp.Security.CentralAuthClientCredentials, MyApp"> 
        <clientCertificate findValue="localhost" x509FindType="FindBySubjectName" storeLocation="CurrentUser" storeName="My" /> 
        <serviceCertificate> 
         <defaultCertificate findValue="localhost" x509FindType="FindBySubjectName" storeLocation="CurrentUser" storeName="My" /> 
         <authentication certificateValidationMode="None" revocationMode="NoCheck" /> 
        </serviceCertificate> 
       </clientCredentials> 
      </behavior> 
     </endpointBehaviors> 

这种配置是完全100%与用户名的认证工作。它使用证书来加密消息的用户名和密码。然后我改为自定义ClientCredentials。

在运行时,这里是被我CentralAuthClientCredentials设置的属性:

this.ClientCertificate = System.ServiceModel.Security.X509CertificateInitiatorClientCredential 
this.ClientCertificate.Certificate = null 
this.ServiceCertificate = System.ServiceModel.Security.X509CertificateRecipientClientCredential 
this.ServiceCertificate.DefaultCertificate = null 

那么,为什么在配置组实际实例化对象中定义的客户端和服务默认证书?看起来好像WCF完全忽略了XML标签!

是否有一些代码可以使用,也许在凭据的构造函数中,手动从配置中获取这些证书?

感谢您的帮助!


更新

我是个白痴。我想到了。 WCF实际上是与证书正确设置创建我的实例,但在我的WCF客户端,我有以下删除/添加系列,我认为我从MSDN例如复制:

this.ChannelFactory.Endpoint.Behaviors.Remove<ClientCredentials>(); 
this.ChannelFactory.Endpoint.Behaviors.Add(new CentralAuthClientCredentials()); 
return base.Channel.MyServiceMethod(); 

删除旧凭据并添加我自己的自定义。但是,这是一个没有设置证书的新实例!哎呀!

+0

你可以显示正在使用的绑定吗? – 2009-02-22 07:01:03

回答

1

所以,我可以标记这个作为回答,我加入我自己的解决方案,这是从,使一个新的凭证,客户端删除此代码:

this.ChannelFactory.Endpoint.Behaviors.Remove<ClientCredentials>(); 
this.ChannelFactory.Endpoint.Behaviors.Add(new CentralAuthClientCredentials()); 

和使用已经被设定的一个WCF,而不是调用它的Remove()。

相关问题