none
Error when trying to pass information to membership provider RRS feed

  • Question

  • I built a WCF service that uses a membership provide to provide authorization for my client and to manage users/roles etc. So far the authorization works great.

    I am trying to give my client the ability to register new users, so I have decided to interface the sql membership provider code from within my service and then call those methods from the client, since I haven't seen a way to directly call upon the SQL provider from a client without Client Application Services.

    I tried interfacing the CreateUser method in the service and when I call it from the client to create a new user I get this error and can't figure out what is going wrong:

    The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework SDK documentation and inspect the server trace logs.

    Here is the code from my service that calls the membership provider directly.

    public string RegisterUser(string username, string password, string email,
                                                       string passwordquestion, string passwordanswer, bool isapproved)
            {
                MembershipCreateStatus status;
                SqlMembershipProvider mProvider = new SqlMembershipProvider();
                mProvider.CreateUser(username, password, email, passwordquestion, passwordanswer, true, null, out status);
    
                switch (status)
                {
                    case MembershipCreateStatus.DuplicateUserName:
                        return "Username already exists. Please enter a different user name.";
    
                    case MembershipCreateStatus.DuplicateEmail:
                        return "A username for that e-mail address already exists. Please enter a different e-mail address.";
    
                    case MembershipCreateStatus.InvalidPassword:
                        return "The password provided is invalid. Please enter a valid password value.";
    
                    case MembershipCreateStatus.InvalidEmail:
                        return "The e-mail address provided is invalid. Please check the value and try again.";
    
                    case MembershipCreateStatus.InvalidAnswer:
                        return "The password retrieval answer provided is invalid. Please check the value and try again.";
    
                    case MembershipCreateStatus.InvalidQuestion:
                        return "The password retrieval question provided is invalid. Please check the value and try again.";
    
                    case MembershipCreateStatus.InvalidUserName:
                        return "The user name provided is invalid. Please check the value and try again.";
    
                    case MembershipCreateStatus.ProviderError:
                        return "The authentication provider returned an error. Please verify your entry and try again. If the problem persists, please contact your system administrator.";
    
                    case MembershipCreateStatus.UserRejected:
                        return "The user creation request has been canceled. Please verify your entry and try again. If the problem persists, please contact your system administrator.";
    
                    default:
                        return "An unknown error occurred. Please verify your entry and try again. If the problem persists, please contact your system administrator.";
                }
    
    
            }

    Here is the code I am calling from my client:

    
    
    private void CreateUser_Click(object sender, RoutedEventArgs e)
            {
                wsBasicAuthService.BasicAuthService c = new wsBasicAuthService.BasicAuthService();
                c.Credentials = new NetworkCredential(txtUserName.Text, txtPassword.Password);
                c.RegisterUser("myUserName", "password", "email@test.com", "question", "answer", true, true);
    
    
            }

    I have noticed that it adds an extra parameter by itself to the c.RegisterUser argument call "isApprovedSpecified", although I don't think that has anything to do with it.

    I am new to memberships and services and having a hard time switching over to C# from vb.net so if anyone could steer me in the right direction I would be more than appreciative.


    Friday, March 22, 2013 6:56 AM

All replies

  • Hi Joe.

    Set includeExceptionDetailsInFaults to true in config and you should see the error.

    <behaviors>
                <serviceBehaviors>

                   <behavior name="<name of your behavior>">
                        <serviceDebug includeExceptionDetailInFaults="true"/>
                    </behavior>
                </serviceBehaviors>
            </behaviors>

    Br,

    JAXN


    Please mark posts as answers/helpful if it answers your question/or helped you solve your problem.
    MCTS: .NET Framework 4, Service Communication Applications

    Monday, March 25, 2013 12:29 PM