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