gpt4 book ai didi

wcf - 如何为WCF netTcpBinding配置用户名/密码身份验证?

转载 作者:行者123 更新时间:2023-12-04 13:21:10 25 4
gpt4 key购买 nike

我希望能够将用户名/密码身份验证与nettcpbinding一起使用,这可能吗? (UserNamePasswordValidator或类似的名称),没有Windows身份验证。

我正在使用代码配置所有内容,因此在任何示例中,请仅使用代码,而不使用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";

关于wcf - 如何为WCF netTcpBinding配置用户名/密码身份验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3922836/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com