views:

21

answers:

1

In my authentication service, I would like to call methods (query or invoke) on my User service to validate credentials. So, for example:

    protected override AuthUser ValidateCredentials(string name, string password, 
        string customData, out string userData)
    {
        AuthUser user = null;
        userData = null;

        using (UserService svc = new UserService())
        {

            if (the result of a call on UserService shows a valid username/password)
            {
                //Create the user object
                user = new AuthUser()
                {
                    Name = name,
                    UserId = // that user's UserId
                };
            }

            if (user != null)
            {
                //Set custom data fields for HTTP session
                userData = user.UserId.ToString();
            }
        }

        return user;
    }

The results I'm finding when searching for things like "call ria service from another ria service" and similar are unrelated to actually calling one from another. Am I doing something wrong from a paradigm point of view? If not, how the heck do you do this? :)

A: 

Aggregating DomainServices when all you want to do is Query is pretty easy. Something like

new MyDomainService().GetUser(userName)

should work just fine. However, when you're trying to Submit or Invoke it become trickier because you'll need to initialize and dispose the DomainService. It's been a while since I did this, but I think you can override Initialize and Dispose in your parent DS to call through to the methods in your child DS. For submitting, you won't be able to call the methods directly. Instead you'll need to create a ChangeSet and call the DS.Submit method.

Also, for your scenario, it might be worth checking out the custom authentication sample here. It's a slightly different approach for what you're trying to do.

Kyle McClellan
Well, don't I feel like a tool :P. I didn't have a GetUser(userName). Instead, I had only the GetUsers() that I was trying to .Where() or use LINQ on. Neither of those worked out for some very complicated reasons (try it for fun sometime :). Once I added a GetUser that returned a single User object, I was golden. Thanks!
David Moye

related questions