2013-10-14 2 views
1

사용자 이름과 암호를 사용할 때 WCF 서비스에 약간 새로운 기능이 있습니다. 내 웹 서비스를 사용자 이름과 암호로 보호하기 위해 http://www.codeproject.com/Articles/96028/WCF-Service-with-custom-username-password-authenti에있는 자습서를 따랐습니다.사용자 이름과 암호를 사용하는 WCF 서비스

<?xml version="1.0" encoding="UTF-8"?> 

<configuration> 

    <system.web> 
    <compilation debug="false" targetFramework="4.5" /> 
    <httpRuntime targetFramework="4.5" /> 
    </system.web> 

    <system.serviceModel> 
    <services> 
     <service behaviorConfiguration="NewBehavior0" name="TService"> 
     <endpoint address="mex" binding="mexHttpBinding" contract="ITechnology" /> 
     </service> 
    </services> 
    <bindings> 
     <wsHttpBinding> 
     <binding name="NewBinding0"> 
      <security> 
      <message clientCredentialType="Certificate" /> 
      </security> 
     </binding> 
     </wsHttpBinding> 
    </bindings> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="NewBehavior0"> 
      <serviceCredentials> 
      <clientCertificate> 
       <authentication certificateValidationMode="PeerTrust" /> 
      </clientCertificate> 
      <serviceCertificate findValue="Server" storeLocation="CurrentUser" 
      storeName="TrustedPeople" x509FindType="FindBySubjectName" /> 
      <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="TService, Services1"/> 
      </serviceCredentials> 
      <serviceMetadata httpGetEnabled="true" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> 
    </system.serviceModel> 
    <system.webServer> 
    <directoryBrowse enabled="true" /> 
    </system.webServer> 
</configuration> 

지금 난 내 브라우저에서 WDSL을 볼 수 있으며 로컬 예상대로 내가 인증서 작동하는 아래

내 구성 파일입니다. WCF 테스트 도구를 사용하여 서비스에 연결할 때 사용자 이름과 암호를 묻지 않습니다.

게시 된 링크에 따르면 마지막 단계 (사용자 이름과 암호를 전달하는 코드 추가)조차하지 못했지만 서비스에 계속 연결하여 모든 데이터를 검색 할 수 있습니다.

무엇을 놓치 셨나요? 그리고 사용자/서비스 만 데이터를 검색 할 수 있도록 허용하는 서비스를 어떻게 제한 할 수 있습니까?

편집 1 :

링크 CodeProject의 페이지의 빠른 검토 결과
<system.serviceModel> 
    <services> 
     <service behaviorConfiguration="NewBehavior0" name="TechService"> 
     <endpoint address="mex" binding="mexHttpBinding" contract="ITechService" /> 
     <endpoint address="TechService.svc" binding="wsHttpBinding" bindingConfiguration="" contract="ITechService" /> 
     </service> 
    </services> 
    <bindings> 
     <wsHttpBinding> 
     <binding name="NewBinding0"> 
      <security> 
      <message clientCredentialType="UserName" /> 
      </security> 
     </binding> 
     </wsHttpBinding> 
    </bindings> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="NewBehavior0"> 
      <serviceCredentials> 
      <clientCertificate> 
       <authentication certificateValidationMode="PeerTrust" /> 
      </clientCertificate> 
      <serviceCertificate findValue="Server" storeLocation="CurrentUser" 
       storeName="TrustedPeople" x509FindType="FindBySubjectName" /> 
      <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="TechService, Services1"/> 
      </serviceCredentials> 
      <serviceMetadata httpGetEnabled="true" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> 
    </system.serviceModel> 
    <system.webServer> 
    <directoryBrowse enabled="true" /> 
    </system.webServer> 
</configuration> 
+0

서비스 요소 및 끝점 요소에는 정규화 된 이름 즉 namespace.TService 및 namespace.ITechnology가 있어야합니다. 귀하의 구성에 따라 엔드 포인트가 적절한 바인딩 메커니즘을 사용하고 있지 않습니다. wsHttpBinding 또는 basicHttpBinding (전송 보안 포함) – Rajesh

답변

1

는, 설정 파일은 어떤 엔드 포인트 실제로 클라이언트 자격 증명 유형을 사용하고 있는지 표시하지 않는 (약간을 것 같다). 은 "NewBinding0"

는 clientCredentialType = "인증"을 지정하지만, 문서의 값이어야 나타냄

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

는 또한 서비스 정의가 단지 "MEX"(메타) 엔드 포인트를 정의한다. clientCredentialType = "UserName"을 지정하는 수정 된 바인딩을 사용하는 wsHttpBinding .. endpoint를 정의하려고 할 것입니다.

<endpoint address="" binding="wsHttpBinding" bindingConfiguration="NewBinding0"/> 

희망 사항.
감사합니다.

+0

감사합니다. 원래 게시물을 편집했고 편집 1에 최신 구성 파일을 포함했지만 예상대로 작동하지 않습니다. 서비스에 연결하기 전에 사용자 이름/비밀번호 또는 유사하게 입력하라는 메시지가 표시 될 것 같은 인상을받습니다. – Computer

+1

편집 1 구성 파일을 기반으로 여전히 bindingConfiguration이 설정되지 않은 것 같습니다 (bindingConfiguration = ""). 바인딩 보안 모드를 적용하려면 bindingConfiguration = "NewBinding0"을 설정해야합니다. – Seymour

관련 문제