2012-01-06 11 views
5

WCFの二重途切れに使用する:動的に設定のx509は、このようなクライアントの設定ファイルに証明書の詳細を指定して、私はX509の証明書との二重WCFサービスに接続してい

<behaviors> 
    <endpointBehaviors> 
    <behavior name="ScannerManagerBehavior"> 
     <clientCredentials> 
     <clientCertificate findValue="ClientName" x509FindType="FindBySubjectName" storeLocation="CurrentUser" storeName="My" /> 
     <serviceCertificate> 
      <authentication certificateValidationMode="PeerTrust" /> 
     </serviceCertificate> 
     </clientCredentials> 
    </behavior> 
    </endpointBehaviors> 
</behaviors> 

、その後に接続するコード

DuplexChannelFactory<IScannerManager> _smFactory 
= new DuplexChannelFactory<IScannerManager>(instanceContext, nameOfEndPoint); 
var _commsChannel = _smFactory.CreateChannel(); 

コードでプログラムで使用されるクライアント証明書名を指定する必要があります。私がそれをすることは可能ですか?私は私自身のx509Certificate2クラスを作成することができていることがわかりますが、私はfindValue="clientName"ビットを設定/変更するかどうかはわかりません...

おかげ

+1

ClientCertificateプロパティの使用については、http://msdn.microsoft.com/en-us/library/system.servicemodel.description.clientcredentials.clientcertificate.aspxを参照してください。 このリンクも参照してくださいhttp://stackoverflow.com/questions/2406136/wcf-certificates-without-certificate-storeこれにはチャンネルのエンドポイント動作でこのプロパティにアクセスする方法を示すスニペットがあります。 – wal

答えて

2

オクラホマので、WALから役に立つコメント(感謝を使って! )私はそれを働かせることができた。私が直面した問題は、コードでクライアントの設定の一部を動的に設定しようとすると、.configのいずれも使用できないことをコードですべて定義する必要があるという発見でした。だから、それはほとんどあるいは全くありません。少なくともそれは私の経験でした。

だから、私のために、私はこれをしなければならなかった。私の設定を置き換え

var binding = new NetTcpBinding(); 
binding.Security.Mode = SecurityMode.Transport; 
binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Certificate; 
binding.Security.Transport.ProtectionLevel = ProtectionLevel.EncryptAndSign; 
binding.Security.Message.ClientCredentialType = MessageCredentialType.Windows; 

var identity = new DnsEndpointIdentity("localhost"); 
Uri uri = new Uri("tcp:URI goes here"); 
var address = new EndpointAddress(uri, identity, new AddressHeaderCollection()); 

_smFactory = new DuplexChannelFactory<IScannerManager>(instanceContext, binding, address); 

_smFactory.Credentials.ClientCertificate.SetCertificate(StoreLocation.CurrentUser, StoreName.My, X509FindType.FindBySubjectName, "CustomCertificateNameHere"); 
_commsChannel = _smFactory.CreateChannel(); 

関連する問題