通過WCF使用客戶端證書憑據從ACS獲取令牌是一種很好的支持方案。
有一個ACS示例可以執行WCF客戶端證書身份驗證here,查找Acs2CertificateBindingSample。興趣點是如何創建一個獲得來自ACS令牌的綁定:
public static Binding CreateServiceBinding(string acsCertificateEndpoint)
{
return new IssuedTokenWSTrustBinding(CreateAcsCertificateBinding(), new EndpointAddress(acsCertificateEndpoint));
}
public static Binding CreateAcsCertificateBinding()
{
return new CertificateWSTrustBinding(SecurityMode.TransportWithMessageCredential);
}
,以及如何創建使用此綁定,以及如何指定客戶端證書憑據通道工廠:
ChannelFactory<IStringService> stringServiceFactory = new ChannelFactory<IStringService>(Bindings.CreateServiceBinding(acsCertificateEndpoint), serviceEndpointAddress);
// Set the service credentials and disable certificate validation to work with sample certificates
stringServiceFactory.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
stringServiceFactory.Credentials.ServiceCertificate.DefaultCertificate = GetServiceCertificate();
// Set the client credentials.
stringServiceFactory.Credentials.ClientCertificate.Certificate = GetClientCertificateWithPrivateKey();
該示例不使用服務總線,只是一個簡單的「IStringService」接口,但如果將NetTcpRelayBinding併入綁定組合中,則相同的機制應適用於您的方案。