WCF Net.Tcp绑定和customUserNamePasswordValidatorType
我有一个带有Net.Tcp绑定的WCF服务,我的服务器配置是WCF Net.Tcp绑定和customUserNamePasswordValidatorType,wcf,nettcpbinding,Wcf,Nettcpbinding,我有一个带有Net.Tcp绑定的WCF服务,我的服务器配置是 <?xml version="1.0" encoding="utf-8" ?> <configuration> <system.serviceModel> <behaviors> <serviceBehaviors> <behavior name=""> <serviceMetadata httpG
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true"/>
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom"
customUserNamePasswordValidatorType="Service.PlainUserNameValidator, Service" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="Service.TestService">
<endpoint address="" binding="netTcpBinding" contract="Service.ITestService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8732/Service/TestService/" />
<add baseAddress="http://localhost:8001/service/TestServiceMex/" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
</configuration>
我在配置文件中注册的自定义用户名验证程序类是
namespace Service
{
using System;
using System.IdentityModel.Selectors;
public class PlainUserNameValidator : UserNamePasswordValidator
{
public override void Validate(string userName, string password)
{
Console.WriteLine("Requesting username {0} and password {1}.", userName, password);
}
}
}
然而,当客户端调用时,验证程序似乎从未启动
为Net.Tcp
绑定启用customUserNamePasswordValidatorType
需要注意的任何特殊技巧?两点:
您尚未包含证书,您应该这样做以确保客户端凭据的完整性,如果必须,请设置一个临时证书,并将其添加到服务凭据中
<serviceCertificate
findValue="localhost"
x509FindType="FindBySubjectName"
storeLocation="CurrentUser"
storeName="My" />
您还没有指定任何安全性—要使其工作,客户端和服务端点都需要在其绑定上启用用户名和密码身份验证模式
<netTcpBinding>
<binding name="tcpWithMessageSecurity">
<security mode="Message" >
<message clientCredentialType="UserName"/>
</security>
</binding>
</netTcpBinding>
然后
然后,说出你的行为并将其添加到上一行。两点:
您尚未包含证书,您应该这样做以确保客户端凭据的完整性,如果必须,请设置一个临时证书,并将其添加到服务凭据中
<serviceCertificate
findValue="localhost"
x509FindType="FindBySubjectName"
storeLocation="CurrentUser"
storeName="My" />
您还没有指定任何安全性—要使其工作,客户端和服务端点都需要在其绑定上启用用户名和密码身份验证模式
<netTcpBinding>
<binding name="tcpWithMessageSecurity">
<security mode="Message" >
<message clientCredentialType="UserName"/>
</security>
</binding>
</netTcpBinding>
然后
然后,命名您的行为并将其添加到上面的行中