WCF 서비스를 처음 사용합니다. 내 WCF 서비스에 액세스 권한을 부여하기 전에 basichttpbinding으로 WCF 서비스를 만들어 사용자 지정 인증 메커니즘을 만들고 싶습니다. 나는 보안 모드 = 전송 및 clientcredentialtype = basic을 사용했습니다. 내 사용자 이름과 암호의 유효성을 검사하는 사용자 정의 유효성 검사기 함수를 작성했습니다.WCF 사용자 이름 인증이 작동하지 않습니다.
검증 기능
그래서 난 내 서비스를 실행할 때마다 여기에 문제가, 내가 로그인 대화 상자를 얻을 것을 나는 사용자 이름과 암호를 (입력 된이 내 서비스 설정 파일< ?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<identity impersonate="false" />
</system.web>
<system.serviceModel>
<diagnostics>
<endToEndTracing activityTracing="true" messageFlowTracing="true" propagateActivity="true"></endToEndTracing>
</diagnostics>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpEndpointBinding">
<security mode="Transport">
<transport clientCredentialType="Basic" />
<!-- <message clientCredentialType="UserName" />-->
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="ServiceBehavior" name="Service">
<endpoint address="" binding="basicHttpBinding" name="BasicHttpEndpoint" bindingConfiguration="BasicHttpEndpointBinding" contract="IService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="false" />
<!-- 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="false" />
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="CustomValidator.MyCustomValidator, App_Code" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<security>
<authentication>
<basicAuthentication enabled="true" />
<anonymousAuthentication enabled="false" />
<windowsAuthentication enabled="false" />
</authentication>
</security>
</system.webServer>
</configuration>
입니다
namespace CustomValidator
{
public class MyCustomValidator : UserNamePasswordValidator
{
public override void Validate(string userName, string password)
{
// This isn't secure, though!
if ((userName != "check") || (password != "check"))
{
throw new SecurityTokenException("Validation Failed!");
}
}
}
}
내 유효성 검사기는 사용자 이름과 비밀번호가 모두 같을 것으로 예상합니다.) 정상적인 경우 (인증 메커니즘없이) 사용하던 서비스 세부 정보 페이지가 표시되지 않습니다. 내가 뭘 놓치고 있는지 모르겠다. 내 상황에서는 문제가되는 구성에서 모두 같지만 여전히 실수를 발견 할 수 없다.