【发布时间】:2016-02-21 04:14:23
【问题描述】:
您好,我正在使用带有 CustomUserNameValidator 的 WCF,我正在使用 Visual Studio 本地 iis,
--------- WCF 应用程序--
namespace AuthenticateWCF
{
public class CustomUserNameValidator : System.IdentityModel.Selectors.UserNamePasswordValidator
{
public override void Validate(string userName, string password)
{
if (userName == null && password == null)
throw new ArgumentNullException();
if (!(userName == "rrr" && password == "ppp"))
throw new FaultException("incorrect password");
}
}
}
我的网络配置文件:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="false"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom"
customUserNamePasswordValidatorType="AuthenticateWCF.CustomUserNameValidator, AuthenticateWCF"/>
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="SecureBasic">
<security mode="TransportWithMessageCredential">
<message clientCredentialType="UserName"/>
</security>
</binding>
<binding name="wsHttp">
<security mode="TransportWithMessageCredential">
<message clientCredentialType="UserName" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<protocolMapping>
<add binding="basicHttpBinding" scheme="http" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
在我的测试项目中调用这个服务时,
ServiceReference1.Service1Client _client = new ServiceReference1.Service1Client();
_client.ClientCredentials.UserName.UserName = "a";
_client.ClientCredentials.UserName.Password = "bb";
var result = _client.GetData(5);
客户端 web 配置文件,这里我使用 TransportWithMessageCredential 来验证用户名
<binding name="BasicHttpBinding_IService1" >
<security mode="TransportWithMessageCredential">
<message clientCredentialType="UserName"/>
</security>
</binding>
但是当我使用它时,我得到了错误
他提供的 URI 方案“http”无效;预期为“https”。
我知道我们可以更改安全模式,但如果我更改了这将不会验证用户。
请帮帮我。
谢谢
【问题讨论】:
标签: c# asp.net asp.net-mvc wcf forms-authentication