2010-12-01 4 views
0

WCF 서비스와 상호 작용해야하는 WP7 앱을 만들려고합니다.
내가 원하는 것은 userName/password를 전달하고 WCF 서비스에서 그것을 보는 것입니다.WCF - 서비스 내에서 Identity.UserName을 가져올 수 없습니다.

 Service1Client proxy = new Service1Client(); 
     proxy.ClientCredentials.UserName.UserName= "[email protected]"; 
     proxy.ClientCredentials.UserName.Password = "abc"; 

코드 우리는 인증 된 이름을 얻기 위해 서비스에 노력했다 (하지만 우리는 대신 창 정체성을 가지고 - MYPC \ myLogin으로) 여기

HttpContext.Current.User.Identity.Name 

클라이언트 설정

<configuration> 
<system.serviceModel> 
    <bindings> 
     <basicHttpBinding> 
      <binding name="BasicHttpBinding_IService1" maxBufferSize="2147483647" 
       maxReceivedMessageSize="2147483647"> 
       <!--<security mode="None" />--> 
       <security mode="TransportCredentialOnly"> 
       <!--<transport clientCredentialType="Basic" />-->     
       </security> 
      </binding> 
     </basicHttpBinding> 
    </bindings> 
    <client> 
     <endpoint address="http://localhost:45148/Service1.svc" binding="basicHttpBinding" 
      bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1" 
      name="BasicHttpBinding_IService1" /> 
    </client> 
</system.serviceModel> 

에게이다 그리고 여기에 서버 설정이 있습니다

,363,210
 <?xml version="1.0"?> 
     <configuration> 
      <system.web> 
      <compilation debug="true" targetFramework="4.0" /> 
      </system.web> 
      <system.serviceModel> 
      <behaviors> 
       <serviceBehaviors > 
       <behavior> 
        <!-- 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="true"/> 
        <serviceCredentials> 
        <userNameAuthentication userNamePasswordValidationMode="Custom" 
        customUserNamePasswordValidatorType="WP7Service.WpfCustomValidator, WP7Service" /> 
        </serviceCredentials> 
       </behavior> 
       </serviceBehaviors> 
      </behaviors> 
      <bindings> 
       <basicHttpBinding> 
       <binding name="BasicHttpBinding_IService1"> 
        <security mode="TransportCredentialOnly"> 
        <transport clientCredentialType="None" /> 
        </security> 
       </binding> 
       </basicHttpBinding> 
      </bindings> 
      <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" /> 
      </system.serviceModel> 
      <system.webServer> 
      <modules runAllManagedModulesForAllRequests="true"/> 
      </system.webServer> 
     </configuration> 

또한 나는 cutom 이름 검사기를 가지고 있지만, 그것은 내가 HttpContext.Current.User.Identity.Name 통해 또는 현재의 thread를 통해 서비스 ClientCredentials.UserName.UserName를 볼 수 있도록 클라이언트와 서비스를 구성하는 방법을 보여주기 위해 대답을 원하는

public class WpfCustomValidator : 
     System.IdentityModel.Selectors.UserNamePasswordValidator 
{ 
    public override void Validate(string userName, string password) 
    { 
     if (userName == null || password == null) 
     { 
      throw new ArgumentNullException(); 
     } 
     var rf = WindsorAccessor.InitializeRepositoryFactory(userName); 

     if (!ValidateLogOn(rf, userName, password)) 
     { 
      throw new FaultException("Incorrect Username or Password"); 
     } 
    } 
} 

를 호출되지 않습니다 신원 (또는 다른 방법).

답변

1

Dominick Baier shows you how do to do this 그의 블로그에 있습니다.

서비스가 clientCredentialType = "None"(즉, 인증 없음)으로 구성되어 있으므로 사용자 정의 유효성 검사기 코드가 호출되지 않습니다.

+0

아직 테스트하지는 않았지만 우리에게 필요한 것 같습니다. tnx. –

+0

참고 - 링크가 끊어졌습니다. –

관련 문제