Export to GitHub

aspnetserve - issue #9

Windows Service Server


Posted on Jul 8, 2008 by Happy Kangaroo

The current simple UI for the server should remain as-is. It provides a clutter free illustration of how to create a functional server, and it is easy to use in a hurry.

However, for more advance server features a more advanced server will be needed. Therefore I propose adding a Windows service backed server that can be configured via XML. This initial feature will not provide a UI for configuring the server, instead the XML will need to be manually edited. Future feature requests will build a UI.

Comment #1

Posted on Jul 9, 2008 by Happy Kangaroo

Changed ticket status to "Started".

Comment #2

Posted on Jul 15, 2008 by Happy Elephant

You could use this Windows service library for hosting it: http://www.hoytsoft.org/serviceBase.aspx

It takes care of UAC in Vista (and later) for you. For example, to host a WCF service, all you need to do is:

public static void Main(string[] args) { bool pleaseStop = false; ManualResetEvent evt = new ManualResetEvent(false);

ServiceBase.RunService(args, new SimpleService(
    "WCF_Server",
    "WCF Hosting Service",
    "Hosts a WCF service",
    null,

    /* Start */
    delegate(SimpleService Service, object Param) {
        ServiceHost selfHost = new ServiceHost(typeof(WCFHost), 

serviceURI); try { selfHost.AddServiceEndpoint(typeof(IWCFHost), new WSHttpBinding(SecurityMode.None), "WCFService"); ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); smb.HttpGetEnabled = true; selfHost.Description.Behaviors.Add(smb); selfHost.Open();

            //Wait until we're asked to stop
            while (!pleaseStop) {
                if (Service.Debug) {
                    Console.WriteLine("Press <ENTER> to 

exit"); Console.ReadLine(); Service.ServiceTestStop(); } evt.WaitOne(10 * 1000, false); }

            selfHost.Close();
        } catch (Exception ex) {
            Debug.WriteLine(ex);
        } finally {
            selfHost.Abort();
            evt.Close();
        }
        Console.WriteLine("Stopped");
    },

    /* Stop */
    delegate(SimpleService Service, object Param) {
        Console.WriteLine("Please Stop");
        pleaseStop = true;
        evt.Set();
    }
));

}

Comment #3

Posted on Jul 15, 2008 by Happy Elephant

I also have an extensive XML configuration library that complements this very well. It already has support for connection strings, forms authentication, url rewriting, e-mailing (w/ templating), localization, etc. on a per-machine basis. IOW, you can create a basic configuration, and then choose to override sections on a per-machine basis (e.g. the connection string is different on different machines). Plus it's easy to add new, type-safe settings. Let me know if you're interested. It's licensed under the CPOL (http://www.codeproject.com/info/cpol10.aspx), so it's very liberal and shouldn't clash w/ your license.

Comment #4

Posted on Jul 18, 2008 by Happy Kangaroo

I have completed the windows service.

Status: Fixed

Labels:
Type-Enhancement Priority-Medium Milestone-Release1.3