2012-03-22 5 views
1

인증을 작동시키려는 테스트 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> 
+0

일반적으로 브라우저와 같은 클라이언트는 자격 증명을 요구합니다. 당신이 테스트 콘솔 어플리케이션을 코딩하지 않았기 때문에 테스트 콘솔 어플리케이션에 프롬프트가 표시되지 않습니다. 자격 증명을 제공하지 않으면 해당 서비스 호출이 실패한 것입니다. 서버 구성에 Binding1 biding으로 서비스를 바인딩했는지 확인하십시오. – VinayC

+0

@VinayC - 어디서 볼 수 있습니까? 내 편집을 봅니다. 내 서비스의 전체 web.config 파일이 포함되어 있습니다. – CallumVass

답변

0

잘못된 바인딩을 사용하고있는 것처럼 보입니다. 클라이언트는 BasicHttp 서버에서 WsHttpBinding을 정의하는 동안 바인딩.

0

WCF/IIS는 설정이 필요없는 서비스를 마술처럼 연결합니다 (이 기능의 이름을 공개적으로 기억할 수는 없습니다 ...). 그러나 몇 가지 사용자 정의 바인딩 구성을 정의하고 있습니다. 괜찮습니다.하지만 이것을 사용하도록 서비스에 지시해야합니다.

당신은 당신 서버의 설정에 <service> 요소를 추가 할 필요가, 무엇인가 : 또한

<system.serviceModel> 
    ... 
    <services> 
     <service name="FullClassNameOfYourService"> 
     <endpoint binding="wsHttpBinding" 
        bindingConfiguration="Binding1" 
        contract="FullClassNameOfYourServiceContract" /> 
     </service> 
    </services> 

, 사실 클라이언트 설정은 wsHttpBinding 요소가 HTTPS 웹 사이트를 사용할 수 없습니다 제안이 포함되어 있지 않습니다 귀하의 서비스를 호스팅합니다.

+0

이제 계약 이름 'MyAPI.IService1'을 'Service1'서비스에서 구현 한 계약서 목록에서 찾을 수 없습니다. – CallumVass

+0

'name' 속성의 값은 단지 "Serivce1"입니까? 계약 유형에 따라 서비스 이름이 "MyAPI.Service1"이어야한다고 생각합니다. 클래스 이름도 네임 스페이스가 필요합니다. –

+0

나는이 세트가'<서비스 이름 = "MyAPI.Service1"> <엔드 포인트 = "있는 wsHttpBinding" bindingConfiguration = "binding1으로" 계약 = "MyAPI.IService1는"/ 바인딩>' – CallumVass

0

귀하의 userName 인증이 잘못되었습니다. customUserNamePasswordValidatorType은 "[정규화 된 어셈블리 + 클래스 이름], [네임 스페이스]"형식이어야합니다. 나는 당신의 공간이 게시물에서 무엇을 이야기하지만, 뭔가 같은 수 없습니다 : 다른 사람이 말했다

<userNameAuthentication userNamePasswordValidationMode="Custom" 
customUserNamePasswordValidatorType="MyNamespace.Authorization , MyNamespace" /> 

으로, 클라이언트가 서비스에 연결하기 위해 동일한 바인딩 유형을 사용해야합니다.

또한 서버 측에서 보안 모드를 none으로 설정했지만 전송 및 메시지 태그가 있습니다. 보안 태그 안에. 보안으로 None을 수행하면 모든 전송 W 메시지 보안 스펙이 무시됩니다. 즉, 보안 모드가 없음 인 경우 클라이언트 자격 증명 유형이 무시되므로 클라이언트는 인증 할 필요가 없습니다.

+0

나는 그것을 시도했지만 에러를 던지기 때문에 Authorization 클래스를 App_Code에 넣고 사용했다. 이제 보안 유형을 전송에 배치하고 클라이언트와 서버 모두에서 동일한 바인딩 유형 (basicHttpbinding 사용)을 설정했지만 다음 오류가 발생합니다. '제공된 URI 스키마'http '가 유효하지 않습니다. 예상 'https'. 매개 변수 이름 : 통해 ' – CallumVass

+0

"오류"나를 많이 도움이되지 않습니다. 다른 오류가 발생하는 경우 App_Code에 퍼팅하는 것이 효과가 있다는 것을 어떻게 알 수 있습니까? https를 찾고 있다면 전송 수준 보안을 지정했음을 나타냅니다. –

+0

"오류"에 의해, 내가 그것을 App_Code를 사용하기 위해 변경하기 전까지는 오류가 발생했다는 것을 의미합니다. – CallumVass

0

간단한 구성 파일이있는 WCF 4를 사용합니다. 그것은 장점을 가지고 있지만 디버깅하기가 더 어렵습니다.귀하의 사용자 정의 wshttpbinding 적용되지 않습니다 용의자. 좀 더 자세한 설정 (예 : wcf 3.5)을 시도하십시오.

<system.serviceModel> 
    <bindings> 
     <wsHttpBinding> 
     <binding name="NewBinding0"> 
      <security mode="TransportWithMessageCredential"> 
      <message clientCredentialType="UserName" /> 
      </security> 
     </binding> 
     </wsHttpBinding> 
    </bindings> 
    <services> 
     <service behaviorConfiguration="WcfService6.Service1Behavior" 
     name="WcfService6.Service1"> 
     <endpoint address="" binding="wsHttpBinding" bindingConfiguration="NewBinding0" 
      contract="WcfService6.IService1"> 
      <identity> 
      <dns value="localhost" /> 
      </identity> 
     </endpoint> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="WcfService6.Service1Behavior"> 
      <!-- 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> 
    </system.serviceModel> 
관련 문제