2012-05-29 2 views
1

내가 Net.Tcp 바인딩으로 WCF 서비스를 내 서버 구성 내가 customUserNamePasswordValidatorType 켜져 구성에서WCF Net.Tcp 바인딩 및 customUserNamePasswordValidatorType

<?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> 

입니다. 호스트를 시작하는 코드는

class Program 
{ 
    static void Main(string[] args) 
    { 
     using (ServiceHost host = new ServiceHost(typeof(TestService))) 
     { 
      host.Open(); 
      Console.WriteLine("The service is ready."); 
      Console.WriteLine(String.Format("Metadata is at {0}?WSDL", host.Description.Endpoints[0].Address)); 
      Console.WriteLine(); 
      Console.WriteLine("Press <ENTER> to terminate service."); 
      Console.WriteLine(); 
      Console.ReadLine(); 
     } 
    } 
} 

입니다 그리고 발리는 클라이언트가 호출되는 동안 불 것으로 보인다 결코 그러나 설정 파일에 등록 된 내 사용자 지정 사용자 이름 유효성 검사기 클래스는

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); 
     } 
    } 
} 

입니다.

customUserNamePasswordValidatorType을 사용하려면 알아 두어야 할 특별한 트릭이 있습니까?

답변

1

두 지점 :

인증서를 포함를 havent, 당신은 당신이 가지고 서비스 자격 증명이를 추가하는 경우 임시을 설정 클라이언트의 자격 증명의 무결성을 보장하기 위해 그렇게해야한다.

<serviceCertificate 
      findValue="localhost" 
      x509FindType="FindBySubjectName" 
      storeLocation="CurrentUser" 
      storeName="My" /> 

또한 보안을 지정 havent 한 -이 작업을 위해, 클라이언트 및 서비스 엔드 포인트가 바인딩 다음

<netTcpBinding> 
    <binding name="tcpWithMessageSecurity"> 
    <security mode="Message" > 
     <message clientCredentialType="UserName"/> 
    </security> 
    </binding> 
</netTcpBinding> 

<endpoint address="" binding="tcpWithMessageSecurity" contract="Service.ITestService"> 

에 사용자 이름 및 암호 인증 모드를 활성화해야 그런 다음 행동의 이름을 지정하고 위의 행에 추가하십시오.

+0

감사합니다. 시도해 보겠습니다. – hardywang

+0

@ 하디 왕이 ​​효과가 있었나요? – Chris

관련 문제