Pregunta

Tengo un servicio de WCF habilitado para Silverlight, del cual un método Absolutamente requiere El atributo [StaoperationBehavior]. Necesito acceder a los detalles del usuario (autenticación de formularios) para el usuario, pero la membresía.getuser () falla mientras se aplica el atributo [StaoperationBehavior].

es decir

    [STAOperationBehavior]
    [OperationContract]
    public string DoWork(int inputStuff)
    {
     Membership.GetUser();//Fails
    }

pero

    //NOT ON STA THREAD
    [OperationContract]
    public string DoWork(int inputStuff)
    {
     Membership.GetUser();//Works
    }

¿Cómo puedo acceder a la información del usuario en este método o proporcionar este método la información del usuario?

¿Fue útil?

Solución

Eventualmente resolví esto eliminando el atributo StaoperationBehavior y ejecutando el método en un hilo STA manualmente:

    //NOT ON STA THREAD
    [OperationContract]
    public void DoWork(int inputStuff)
    {
        //Get the user info while we're not in an STA thread
        var userDetails =  Membership.GetUser();


        System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ThreadStart(delegate
            {
                //Do STA work in here, using the userDetails obtained earlier
            }));

        thread.SetApartmentState(System.Threading.ApartmentState.STA);
        thread.Start();
        thread.Join();
    }

Un poco desordenado pero no encontré otra forma de hacerlo

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top