WCF Preview 4 - ServiceAuthorizationManager & WebFaultException returning xml

Topics: Web Api
Sep 22, 2011 at 1:18 AM
Edited Sep 22, 2011 at 1:18 AM

 

We use the serviceAuthorizationManagerType to validate the user credentials, it seems to work fine on a success authentication but when 
there is an error the WebFaultException returns by default, the response in xml format, we can't turn on the automaticformatting,
how can I return the requested format on this checkAccessCore?

 

 





protected
override bool CheckAccessCore(OperationContext operationContext) { APIUserCredentials _CurrentCredentials = GetAPILoginCredentials(operationContext); API.User _User = new API.User(); _User.UserName = _CurrentCredentials.Username; _User.Password = _CurrentCredentials.Password; _User.APIKey = _CurrentCredentials.APIKey; _User.web_CheckAPIPartnersCredentials(); if (_User.UserId > 0) { _IsAuthenticated = true; GenericIdentity identity = new GenericIdentity(_User.UserId.ToString()); GenericPrincipal principal = new GenericPrincipal(identity, "UserRole".Split(',')); System.Threading.Thread.CurrentPrincipal = principal; HttpContext.Current.User = principal; } else { _APILoggedStatus.SessionID = ""; _APILoggedStatus.Success = false; _APILoggedStatus.Message = "Invalid Credentials"; _IsAuthenticated = false; throw new WebFaultException<APISessionStatus>(_APILoggedStatus, HttpStatusCode.Unauthorized); } return _IsAuthenticated; }