我原以为基本上可以从此切换客户端凭据:
var clientCredentials = new ClientCredentials();
clientCredentials.UserName.UserName = "MyUserName"
clientCredentials.UserName.Password = "MyPassword"
至:
var clientCredentials = new ClientCredentials();
clientCredentials.ClientCertificate.Certificate = myX509Certificate;
然后创建一个 wsTrustChannel 来获取安全令牌。
wsTrustChannelFactory.SetCredentials(clientCredentials);
var channel = _wsTrustChannelFactory.CreateChannel(new EndpointAddress(endpointAddress));
var token = channel.Issue(new RequestSecurityToken
{
TokenType = tokenType,
AppliesTo = new EndpointReference(realm),
RequestType = RequestTypes.Issue,
KeyType = KeyTypes.Bearer
}, out requestSecurityTokenResponse);
用户名和密码工作正常,只是使用证书抱怨没有指定用户名。我的印象是令牌发行者会从证书中查找关联的用户。我在哪里错了?