我有一个WSE 3客户端,它使用WSE 3 web-service + STS:
var stsService = new SecurityTokenServiceClient("https://stsurl");
var securityToken = stsService.requestSecurityToken("login", "password");
var st = new SecurityContextToken(securityToken);
transferObject.RequestSoapContext.Security.Tokens.Add(st);
所以安全令牌只是添加到Token的集合中,我们可以通过transferObject调用服务。
但现在我需要使用WCF实现类似的客户端。在这里,我遇到的代码不幸导致验证错误:
var binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
var client = new GeneratedClient(binding, new EndpointAddress("https://serviceurl"));
client.ClientCredentials.IssuedToken.LocalIssuerBinding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
client.ClientCredentials.IssuedToken.LocalIssuerAddress = new EndpointAddress("https://stsurl");
client.ClientCredentials.UserName.UserName = "login";
client.ClientCredentials.UserName.Password = "password";
client.ChannelFactory.ConfigureChannelFactory();
var channel = client.ChannelFactory.CreateChannel();
var requestWrap = new Services.SomeMethodRequest();
requestWrap.ListShipments = request;
var response = channel.SomeMethod(requestWrap);
通过WCF使用STS身份验证是否正确?
答案 0 :(得分:0)
这应该会让你走上正轨
EndpointAddress endpointAddress = new EndpointAddress( OtherSTSAddress );
UserNameWSTrustBinding binding =
new UserNameWSTrustBinding( SecurityMode.TransportWithMessageCredential );
WSTrustChannelFactory factory = new WSTrustChannelFactory( binding, endpointAddress );
factory.Credentials.UserName.UserName = UserName;
factory.Credentials.UserName.Password = Password;
factory.TrustVersion = System.ServiceModel.Security.TrustVersion.WSTrustFeb2005;
WSTrustChannel channel = (WSTrustChannel)factory.CreateChannel();
RequestSecurityToken rst = new RequestSecurityToken(
WSTrustFeb2005Constants.RequestTypes.Issue,
WSTrustFeb2005Constants.KeyTypes.Bearer );
rst.AppliesTo = new EndpointAddress( YourStsAddress );
SecurityToken token = channel.Issue( rst );