2011-04-09 1 views
1

DomainService1은 SOAP 서비스로 제공되는 RIA 도메인 서비스입니다. 이 서비스는 [RequiresAuthentication] 및 [RequiresRole ("xyz")] 특성을 사용하여 보호되었습니다.RIA 도메인 서비스의 인증 문제 (작업에 대한 액세스가 거부 됨)

web.config에서 roleManager를 활성화하고 인증 모드를 Forms로 설정했습니다.

테스트 클라이언트는 인증 및 원격 서비스 작업 호출하려면 다음 코드를 사용 : 나는 auth.Login에 대한 호출이 실제로 올바른 사용자를 반환 볼 수 있습니다

 var auth = new myAuth.AuthenticationDomainServiceSoapClient(); 
     var svc = new mySvc.DomainService1SoapClient(); 

     try 
     { 
      string myCookie; 

      using (new OperationContextScope(auth.InnerChannel)) 
      { 
       var user = auth.Login(svcUser.Text, svcPass.Text, false, string.Empty); 

       var res = (HttpResponseMessageProperty)OperationContext.Current.IncomingMessageProperties[HttpResponseMessageProperty.Name]; 
       myCookie = res.Headers[HttpResponseHeader.SetCookie]; 
      } 

      using (new OperationContextScope(svc.InnerChannel)) 
      { 
       var octx = OperationContext.Current; 
       HttpRequestMessageProperty request = new HttpRequestMessageProperty(); 
       request.Headers["Cookie"] = myCookie; 
       OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = request; 

       var results = svc.GetItems(); 
      } 
     } 
     catch (Exception ex) 
     { 
      MessageBox.Show(ex.Message); 
     } 

을, 그 객체에 난을 볼 수 있습니다 역할이 올바르게 설정되었습니다. 그러나 GetItems에 대한 호출이 실패하고 "작업에 대한 액세스가 거부되었습니다"라는 예외가 발생합니다.

뭔가 내려다 보입니까? 제가 빠뜨린 명백한 것을 볼 수 있습니까? 사전에

감사합니다,

건배, 지안루카.

[편집] 내가이 얻을 이벤트 로그에 그것을 추가 할 : 폼 인증 요청에 실패했습니다. 이유 : 제공된 티켓이 유효하지 않습니다.

이유에 대해 알고 싶습니다.

건배.

답변

0

쿠키에 저장된 데이터가 너무 길 때 비슷한 문제 (예외)가 발생했습니다. 중요한 데이터 만 세션 쿠키에 저장하십시오. 세션 쿠키는 4k로 제한됩니다. 로그인이 성공하더라도 이후의 호출에서 쿠키가 너무 커서 액세스가 거부 된 오류가 발생합니다.

0

answer에 게시 된 RIA Authentication from a Web Services project 질문은 누락 된 링크를 제공하는 것 같습니다.

코드에서 누락 된 추가 단계는 HttpResponseHeader.SetCookie 속성을 읽는 데 사용되는 FormatCookie() 메서드입니다.

/// <summary> 
/// Formats a request cookie string from the cookies received from the authentication service 
/// </summary> 
/// <param name="input">The cookie string received from the authentications service</param> 
/// <returns>A formatted cookie string to send to data requests</returns> 
private static string FormatCookie(string input) 
{ 
    string[] cookies = input.Split(new char[] { ',', ';' }); 
    StringBuilder buffer = new StringBuilder(input.Length * 10); 
    foreach (string entry in cookies) 
    { 
     if (entry.IndexOf("=") > 0 && !entry.Trim().StartsWith("path") && !entry.Trim().StartsWith("expires")) 
     { 
      buffer.Append(entry).Append("; "); 
     } 
    } 
    if (buffer.Length > 0) 
    { 
     buffer.Remove(buffer.Length - 2, 2); 
    } 
    return buffer.ToString(); 
} 

개인적으로 여기 http://blogs.msdn.com/b/davrous/archive/2010/12/03/how-to-open-a-wcf-ria-services-application-to-other-type-of-clients-the-soap-endpoint-3-5.aspx을 설명 CookieManager에 기술을 사용한 후이 작업을 진행하는 데에 FormatCookie() 메소드를 추가했다.