인증을 작동시키려는 테스트 WCF 응용 프로그램을 만들었지 만 메서드를 실행하고 로그인/인증을 요청하지 않습니다.WCF 인증이 자격 증명을 요구하지 않습니다.
<bindings>
<wsHttpBinding>
<binding name="Binding1">
<security mode="Message">
<message clientCredentialType="UserName" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="MyAPI.Authorization, App_Code" />
</serviceCredentials>
은 내 권한 클래스 :
public class Authorization : UserNamePasswordValidator
{
public override void Validate(string userName, string password)
{
if (null == userName || null == password)
{
throw new ArgumentNullException();
}
if (!(userName == "test1" && password == "1tset") && !(userName == "test2" && password == "2tset"))
{
// This throws an informative fault to the client.
throw new FaultException("Unknown Username or Incorrect Password");
// When you do not want to throw an infomative fault to the client,
// throw the following exception.
// throw new SecurityTokenException("Unknown Username or Incorrect Password");
}
}
}
내 Service.svc.cs 클래스
public string Hello(string message)
{
return "You typed: " + message;
}
이 내가 해야하는 건가요 아래 내 WCF 응용 프로그램 내 Web.config의 코드 조각입니다 인증을 요구하거나 클래스 위에이 메소드 위에 어떤 속성을 두어야합니까? 인증을 요청하지 않고 :
public static Test.Service1Client client = new Test.Service1Client();
static void Main(string[] args)
{
Console.WriteLine(client.Hello("hello"));
Console.ReadLine();
}
이 그냥 "안녕하세요 당신은 입력"출력 :
내가 다음 테스트 콘솔 응용 프로그램을 만들었습니다, 여기에 코드입니다. 수행하여 client.Hello("hello")
를 호출하기 전에
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://MyServer/Service1.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService1" contract="Test.IService1"
name="BasicHttpBinding_IService1" />
</client>
</system.serviceModel>
내가 로그인 자격 증명을 설정해야 기대 : 분명하지
client.ClientCredentials.UserName.UserName = "test1";
client.ClientCredentials.UserName.Password = "1tset";
그러나 편집
여기 내의 app.config의 미리보기입니다<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="Binding1">
<security mode="Message">
<message clientCredentialType="UserName" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="MyAPI.Authorization, App_Code" />
</serviceCredentials>
<!-- 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="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
일반적으로 브라우저와 같은 클라이언트는 자격 증명을 요구합니다. 당신이 테스트 콘솔 어플리케이션을 코딩하지 않았기 때문에 테스트 콘솔 어플리케이션에 프롬프트가 표시되지 않습니다. 자격 증명을 제공하지 않으면 해당 서비스 호출이 실패한 것입니다. 서버 구성에 Binding1 biding으로 서비스를 바인딩했는지 확인하십시오. – VinayC
@VinayC - 어디서 볼 수 있습니까? 내 편집을 봅니다. 내 서비스의 전체 web.config 파일이 포함되어 있습니다. – CallumVass