views:

68

answers:

0

Hello,

I'm pretty new to WCF, so this might be a very simple question. I'm implementing a service to be accessed from Silverlight.

I'm using role-based authentication with my own ASP.NET Role and Membership provider implementations. It seems to be configured correctly - I can use PrincipalPermission attributes on methods.

However, I'm trying to implement a method that can be called by both authenticated and unauthenticated users. If it's called by an auth. user, it should return an array of the roles that the user is in. If called by someone unauthenticated, it should return an empty array.

My code is as follows:

        [OperationContract]
        public string[] GetUserRoles()
        {
            if (OperationContext.Current.ServiceSecurityContext.IsAnonymous 
                || !OperationContext.Current.ServiceSecurityContext.PrimaryIdentity.IsAuthenticated)
                return new string[] { };

            return System.Web.Security.Roles.GetRolesForUser();
        }

However, the function always returns an empty array. Microsoft's documentation says to use the RoleService class, but I don't know how to receive an instance of it.

Thank you, Martin