6

nettcpbinding でユーザー名/パスワード認証を使用できるようにしたいのですが、可能ですか? (UserNamePasswordValidator など)、Windows 認証なし。

コードですべてを構成しているため、例では app.config ではなくコードのみを使用してください。

4

1 に答える 1

16

これは私が思いついたものです。コードの一部が必要でないかどうかはわかりません。

サービス ホスト:

        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";
于 2010-10-13T11:15:52.403 に答える