Results 1 to 2 of 2

Thread: [RESOLVED] How do I get my Windows Service to run detached from the client?

Threaded View

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Dunmow,Essex,England
    Posts
    898

    Resolved [RESOLVED] How do I get my Windows Service to run detached from the client?

    Hi All,

    I have a WCF Service library wrapped in a windows service being called from a standard Web App.

    My web app has a reference to the windows service and calls the wcf process on the windows service in the following way:
    Code:
    using (IRSService.RSClient WCF = new RSClient())
                    {
                        WCF.ProcessBorderaux();
                        WCF.Close();
                    }
    In my windows service in my OnStart Event I have the following Code:



    Code:
    Thread t = new Thread(new ThreadStart(RunService));
                try
                {
                   t.Start();
                }
                catch
                {
                    if (t.IsAlive) { t.Abort(); }
                    throw;
                }
    and my RunService method is defined:



    Code:
    protected void RunService()
            {
                sHost = new ServiceHost(typeof(wcfBorderauxIRSService.IRSService));
                sHost.Open();
    
                ServiceEndpoint endpoint = sHost.Description.Endpoints[0];
                EventLog.WriteEntry(endpoint.Contract.Name + " Started" + " listening on " + endpoint.Address + " (" + endpoint.Binding.Name + ")",
                                    System.Diagnostics.EventLogEntryType.Information);
            }
    Once t.start has been initiated, I expect the process to bubble back up the chain and thus become detached from my client. However, The client still seems to be attached after my long running process has been started. and so then the client falls at the closing curly brace of my 'Using' Statement with the following error:

    The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state.

    If I continue, my client crashes, but my service continues as I want.

    How do I gracefully detach my Service from the client once the service has initiated successfully?

    On my WCF Service, I have added to the interface the oneway attribute:

    Code:
    [ServiceContract]
        public interface IRS
        {
            [OperationContract(IsOneWay=true)]
            void ProcessBorderaux();
    and on the Service I have adorned a ServiceBehaviour:

    Code:
        [ServiceBehavior(AutomaticSessionShutdown = false, UseSynchronizationContext = false, InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Single)]
        public class IRSService : IRS.....
    The idea being that with AutomaticSessionShutdown set, the service doesn't shut when the client does. However adding these have made little difference I know receive a timeout error relating to sockets, but it's still the same underlying issue of returning from the service as soon as the process has been called.
    Last edited by Bill Crawley; Apr 8th, 2011 at 05:46 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width