6
我想能够使用用户名/密码认证与NetTcpBinding的,这可能吗? (UserNamePasswordValidator或类似的东西),没有Windows身份验证。如何为WCF NetTcpBinding的配置用户名/密码认证?
我配置与代码的一切,所以请只使用代码,并在任何例子不App.config中。
我想能够使用用户名/密码认证与NetTcpBinding的,这可能吗? (UserNamePasswordValidator或类似的东西),没有Windows身份验证。如何为WCF NetTcpBinding的配置用户名/密码认证?
我配置与代码的一切,所以请只使用代码,并在任何例子不App.config中。
这是我想出了,我不知道,如果一些代码不要求:
服务主机:
ServiceHost host = new ServiceHost(concreteType);
var binding = new NetTcpBinding(SecurityMode.TransportWithMessageCredential, true);
binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
host.AddServiceEndpoint(serviceType, binding, "net.tcp://someaddress:9000/" + name);
host.Credentials.UserNameAuthentication.CustomUserNamePasswordValidator = new CustomUserNameValidator();
host.Credentials.ServiceCertificate.Certificate = new X509Certificate2("mycertificate.p12", "password");
host.Credentials.UserNameAuthentication.UserNamePasswordValidationMode =
UserNamePasswordValidationMode.Custom;
和客户端:
var binding = new NetTcpBinding(SecurityMode.TransportWithMessageCredential, true);
binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
var factory = new ChannelFactory<ISwitchService>(binding,
new EndpointAddress(
new Uri("net.tcp://someaddress:9000/switch")));
factory.Credentials.UserName.UserName = "myUserName";
factory.Credentials.UserName.Password = "myPassword";
谢谢为这样一个很好的明确的答案。帮助了我很多。 – Kelly 2012-11-15 16:43:15