New Posts New Posts RSS Feed: Using DevForce with windows service
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Using DevForce with windows service

 Post Reply Post Reply
Author
amarpai View Drop Down
Newbie
Newbie


Joined: 29-Jul-2013
Posts: 2
Post Options Post Options   Quote amarpai Quote  Post ReplyReply Direct Link To This Post Topic: Using DevForce with windows service
    Posted: 16-Nov-2013 at 12:13pm
We're evaluating DevForce/Cocktail and have found it works great with WCF. Our application has a number of windows services and we've been unable to get it to work.

Does DevForce work with Windows Services? I could not find any examples in the documentation. Here is the sample code. All the MEF instantiations work correctly. However, the application hangs when trying to retrieve from the database. I have tried various things:

- Invoking the myService.ProcessRequests using a TaskFactory.StartNew
- Invoking the ProcessRequests from a Timer.Elapsed event

In all cases, the application hangs at the DB call. What do I do to fix this?

Thanks!

------------------------------------------------------------------------
    internal static class Program
    {
        private static void Main()
        {
            var myService = new MyService();

#if DEBUG
            myService.ProcessRequests();
#else
            var servicesToRun = new ServiceBase[] { myService };
            ServiceBase.Run(servicesToRun);
#endif
        }
    }

    public partial class MyService : ServiceBase
    {
        // Windows service boiler-plate code removed

        protected override void OnStart(string[] args)
        {
            ProcessRequests();
        }

        public void ProcessRequests()
        {
            // _processor is correctly instantiated
            _processor = new MefInstanceProvider<MyProcessor>().GetInstance();
            _processor.ProcessRequests();
        }
    }

    internal class MyProcessor : IDisposable
    {
        // LoginManager is successfully set through MEF using constructor

        public async Task<string> ProcessRequests()
        {
            await _loginManager.LoginAsync(new LoginCredential("Admin", "password", null));
        }
    }

    public class LoginManager : IEntityLoginManager
    {
        // EM is successfully set through MEF using constructor

        public virtual IPrincipal Login(ILoginCredential credential)
        {
            var em = new SecurityEntities(entityManager);
            User user = em.Users.Include(u => u.Contacts)
                          .FirstOrDefault(x => x.Username.ToUpper()
                          .Equals(credential.UserName.ToUpper()));
            // Execution stops at the above line
        }
    }
}
------------------------------------------------------------------------

Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 16-Nov-2013 at 6:29pm
It's likely that the Windows account running the service doesn't have permissions to the database. The debuglog generated by DevForce, and possibly the Event Viewer, should have more information on the exact error.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down