C# WCF自定义身份验证不工作
正在尝试为wcf服务实现简单的“用户名”/“密码”身份验证。但它只是不起作用。没有错误/例外。 以下是web配置代码:C# WCF自定义身份验证不工作,c#,.net,wcf,authentication,wcf-security,C#,.net,Wcf,Authentication,Wcf Security,正在尝试为wcf服务实现简单的“用户名”/“密码”身份验证。但它只是不起作用。没有错误/例外。 以下是web配置代码: <?xml version="1.0"?> <configuration> <system.web> <compilation debug="true" targetFramework="4.0"/> <customErrors mod
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<customErrors mode="Off"/>
</system.web>
<system.serviceModel>
<services>
<service name="XYZService"
behaviorConfiguration="XYZBehavior">
<!-- use base address specified above, provide one endpoint -->
<endpoint address=""
binding="basicHttpBinding"
bindingConfiguration="XYZBinding"
contract="IXYZService" />
<!--<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />-->
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="XYZBinding">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Basic" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="XYZBinding.LicensingServer.CCustomValidatorClass, XYZBinding.LicensingServer"/>
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
没有错误或例外。我能够调用该服务并在没有任何凭据的情况下执行。在本地调试时,不会命中验证方法
我不知道遗漏了什么。该服务是否托管在IIS中?如果是这样,这可能不受支持,因为IIS执行传输端口身份验证。
该服务是否托管在IIS中?如果是这样,这可能不受支持,因为IIS执行传输端口身份验证。
我不是WCF方面的专家,但这些场景中的第一个问题始终是:您确定正在使用此配置吗?。通过更改配置中可能会破坏应用程序的某些内容来检查这一点,如果应用程序仍然工作,它将使用另一个配置:-刚刚更新了“customUserNamePasswordValidatorType”,wcf测试客户端抛出了一个错误。改回原来的。WCF测试客户端运行平稳。您没有向我们展示配置部分中重要和有趣的部分。你有没有真正使用这些绑定配置和安全设置的服务??从你到目前为止发布的内容来看,它看起来不是这样的……嗯,没有定义任何部分。也许这就是问题所在。我将只添加/配置一个并更新此。更新为服务部分。现在,我得到“此服务的安全设置需要“基本”身份验证,但没有为承载此服务的IIS应用程序启用此身份验证。”错误。我不是WCF方面的专家,但这些场景中的第一个问题始终是:您确定正在使用此配置吗?。通过更改配置中可能会破坏应用程序的某些内容来检查这一点,如果应用程序仍然工作,它将使用另一个配置:-刚刚更新了“customUserNamePasswordValidatorType”,wcf测试客户端抛出了一个错误。改回原来的。WCF测试客户端运行平稳。您没有向我们展示配置部分中重要和有趣的部分。你有没有真正使用这些绑定配置和安全设置的服务??从你到目前为止发布的内容来看,它看起来不是这样的……嗯,没有定义任何部分。也许这就是问题所在。我将只添加/配置一个并更新此。更新为服务部分。现在,我得到“此服务的安全设置需要“基本”身份验证,但没有为承载此服务的IIS应用程序启用此身份验证。”错误。
public class CCustomValidatorClass : UserNamePasswordValidator
{
public override void Validate(string userName, string password)
{
if(userName != "Test" || password != "1234567")
{
throw new FaultException("The provided credentials are invalid.");
}
}
}