Silverlight 4 Login InvalidOperationException "UserService operation already in progress"

We get this InvalidOperationException error "working with a user service that is already running" in our Silverlight 4 (OOB with RIA services) when you click the "Login" button, but this does not happen every time, and sometimes several times. If I ignore the error and keep working, it seems to work. Does anyone know what causes this?

EDIT: The project was created using the Silverlight business application template.

Stack trace

in System.ServiceModel.DomainServices.Client.ApplicationServices.AuthenticationService.StartOperation (authentication operation)
in System.ServiceModel.DomainServices.Client.ApplicationServices.AuthenticationService.Login (parameters LoginParameters, Action`1 completeAction, Object userState)
in Reach.SL.LoginUI.LoginForm.LoginButton_Click (object sender, EventArgs e)
in System.Windows.Controls.Primitives.ButtonBase.OnClick () in System.Windows.Controls.Button.OnClick () in System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp (MouseButtonEventArgs e)
in System.Windows.Controls.Control.OnMouseLeftButtonUp (Control ctrl, EventArgs e)
at MS.Internal.JoltHelper.FireEvent (IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)

EDIT (additional information). I was able to consistently reproduce the issue with the new Silverlight Business Application solution and a few minor changes. The problem arises much more on a site where services respond more slowly, so all the changes are faster user input in my dev block. If you start with the Silverlight Business Application and change it to do two things; 1. Show the registration window as soon as it loads. 2. default in some valid credentials (so you do not need to enter them).

Then run the application and press 'enter' (to enter the system) as soon as the screen is displayed, then I will get the error sequentially.

I used Fiddler and it shows that two calls are actually happening ...

/ClientBin/SilverlightBusinessApp-Web-AuthenticationService.svc/binary/GetUser /ClientBin/SilverlightBusinessApp-Web-AuthenticationService.svc/binary/Login 

The error occurs when the first GetUser call is still made when it calls the login. Where does this call from GetUser come from? (this is getting credentials from aspnetDB)

What code can be added so that it does not call Login until the GetUser call is completed? (I tried "WebContext.Current.Authentication.IsBusy", but it does not seem to reset when the getUser call is complete.

+4
source share
1 answer

In the Silverlight business application template, the following line of code can be found in App.xaml.cs in the Application_Startup method.

 WebContext.Current.Authentication.LoadUser(this.Application_UserLoaded, null); 

This line will call GetUser on your AuthenticationService (which is also part of the template). Thus, in essence, this GetUser service GetUser occurs when the application starts, which causes a problem with users starting quickly after the application starts.

If you do not want users to automatically subscribe if they check the Remember Me field, you can safely remove this line from Application_Startup . Another option is to create some LoginHelper class and fire an event in this class when the login is complete. Listen for this event in your entry control and only activate the login button when the initial GetUser call GetUser .

There are several other potential problems, but without knowing the architecture of your project, it is difficult to recommend it. Hope this helps.

+4
source

Source: https://habr.com/ru/post/1342070/


All Articles