none
WCF Windows Service won't start Automatically but does Manually. RRS feed

  • Question

  • Hi,

    I have a WCF Service hosted inside a Windows Service. The Windows Service is run under a user account with permissions to start Windows Services. When Windows Starts the Service fails with an exception. However, if I log on as Administrator the service runs as expected.

    Here's the Exception :

    System.TimeoutException: Client is unable to finish the security negotiation within the configured timeout (00:00:00).  The current negotiation leg is 1 (00:00:00).   ---> System.TimeoutException: The request channel timed out attempting to send after 00:00:00. Increase the timeout value passed to the call to Request or increase the SendTimeout value on the Binding. The time allotted to this operation may have been a portion of a longer timeout. ---> System.TimeoutException: The HTTP request to 'http://localhost:8060/WcfSvc/Service/' has exceeded the allotted timeout of 00:00:00. The time allotted to this operation may have been a portion of a longer timeout.
       at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.SendRequest(Message message, TimeSpan timeout)
       at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
       --- End of inner exception stack trace ---
       at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
       at System.ServiceModel.Security.IssuanceTokenProviderBase`1.DoNegotiation(TimeSpan timeout)
       --- End of inner exception stack trace ---

    Server stack trace: 
       at System.ServiceModel.Security.IssuanceTokenProviderBase`1.DoNegotiation(TimeSpan timeout)
       at System.ServiceModel.Security.SspiNegotiationTokenProvider.OnOpen(TimeSpan timeout)
       at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
       at System.ServiceModel.Security.SymmetricSecurityProtocol.OnOpen(TimeSpan timeout)
       at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
       at System.ServiceModel.Channels.SecurityChannelFactory`1.ClientSecurityChannel`1.OnOpen(TimeSpan timeout)
       at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
       at System.ServiceModel.Security.SecuritySessionSecurityTokenProvider.DoOperation(SecuritySessionOperation operation, EndpointAddress target, Uri via, SecurityToken currentToken, TimeSpan timeout)
       at System.ServiceModel.Security.SecuritySessionSecurityTokenProvider.GetTokenCore(TimeSpan timeout)
       at System.IdentityModel.Selectors.SecurityTokenProvider.GetToken(TimeSpan timeout)
       at System.ServiceModel.Security.SecuritySessionClientSettings`1.ClientSecuritySessionChannel.OnOpen(TimeSpan timeout)
       at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
       at System.ServiceModel.Channels.ReliableChannelBinder`1.ChannelSynchronizer.SyncWaiter.TryGetChannel()
       at System.ServiceModel.Channels.ReliableChannelBinder`1.ChannelSynchronizer.SyncWaiter.TryWait(TChannel& channel)
       at System.ServiceModel.Channels.ReliableChannelBinder`1.ChannelSynchronizer.TryGetChannel(Boolean canGetChannel, Boolean canCauseFault, TimeSpan timeout, MaskingMode maskingMode, TChannel& channel)
       at System.ServiceModel.Channels.ReliableChannelBinder`1.Send(Message message, TimeSpan timeout, MaskingMode maskingMode)
       at System.ServiceModel.Channels.SendReceiveReliableRequestor.OnRequest(Message request, TimeSpan timeout, Boolean last)
       at System.ServiceModel.Channels.ReliableRequestor.Request(TimeSpan timeout)
       at System.ServiceModel.Channels.ClientReliableSession.Open(TimeSpan timeout)
       at System.ServiceModel.Channels.ClientReliableDuplexSessionChannel.OnOpen(TimeSpan timeout)
       at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannel.OnOpen(TimeSpan timeout)
       at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)

    Exception rethrown at [0]: 
       at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
       at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
       at System.ServiceModel.ICommunicationObject.Open(TimeSpan timeout)
       at System.ServiceModel.ClientBase`1.System.ServiceModel.ICommunicationObject.Open(TimeSpan timeout)
       at WindowsService.WCFService.OnStart(String[] args)

    Any ideas what could be causing this?

    Thanks in advance.

    Matt

    Friday, January 11, 2013 3:39 PM

Answers

  • Solution:

    In the Windows Service OnStart event handler, I create a new thread, which poll's (using the WaitForStatus call didn't work) for the WAS service to start. On my system it takes around 25 seconds for that to happen. Once WAS has started I create my WCF Service, and all is well.
    • Marked as answer by MattHousley Tuesday, January 15, 2013 9:27 AM
    Tuesday, January 15, 2013 9:27 AM

All replies

  • So the user you are using to start the service may have permissions to start the service but it lacks permissions to either communicate outward or security. Therefore it fails to start because of the exception and when the service does that it "Timeout" with starting. I believe services much start with in 30 or 60 seconds.

    What you need to do is figure out what permission your current user is missing because Admin obviously has all permissions.

    Thanks,

    Brad

    Friday, January 11, 2013 5:38 PM
  • I think the problem has to do with IE credentials.  The users have the correct credentials set up in their login account, but the Admin account doesn't.

    jdweng

    Friday, January 11, 2013 5:55 PM
  • Hi Brad,

    Thanks for replying.

    What I don't understand is, "Log On" for the service is set to a user account that is different to Administrator which successfully starts the service (manually). But when the service is running it's still running as the user defined in "Log On", not Administrator...

    Surely however I was starting the Windows Service, it should always run under the "Log On" identity, No?

    It sounds like you're saying that starting the service Manually ignores the "Log On" settings, and runs under current user, that's wrong isn't it?

    Matt

    Friday, January 11, 2013 7:48 PM
  • Hi Joel,

    Thanks for replying.

    The Administrator account is able to start the Windows Service manually. But as I put above the service's "Log On" credentials are set to a different user. So surely the Windows Service will be running with those credentials, no?

    Matt

    Friday, January 11, 2013 7:50 PM
  • Brad & Joel,

    I log the current user in the Windows Service, and in both cases, they're using the right 'Log On' user. Not the currently logged on user account that start the service.

    So surely that rules out what both of you have said.

    Any other ideas?

    Thanks


    Matt

    Monday, January 14, 2013 11:22 AM
  • I've got this to work by changing the Services Startup Type from "Automatic" to "Automatic (Delayed Start)". 

    So clearly there's a WCF component that isn't ready/running when Windows starts my service.

    What WCF dependant services need to be running before I can start up a WCF service?

    Thanks

    Matt

    Monday, January 14, 2013 11:56 AM
  • Update:

    My service appears to be failing, because WAS (Windows Process Activation Service) isn't Running when my Service is started.

    Waiting for WAS to start, before starting WCF in my service doesn't seem to work either:

    ServiceController sc = new ServiceController("WAS");
    sc.WaitForStatus(ServiceControllerStatus.Running,TimeSpan.FromTicks(timeout));

    Even with a 5 minute time out, WaitForStatus fails. However, getting the status of the WAS service straight after the time out show's it's running, and my service starts....

    Monday, January 14, 2013 5:05 PM
  • Hi, To get the exact issue, you may need configure tracing for your service.

    Tuesday, January 15, 2013 7:33 AM
  • Solution:

    In the Windows Service OnStart event handler, I create a new thread, which poll's (using the WaitForStatus call didn't work) for the WAS service to start. On my system it takes around 25 seconds for that to happen. Once WAS has started I create my WCF Service, and all is well.
    • Marked as answer by MattHousley Tuesday, January 15, 2013 9:27 AM
    Tuesday, January 15, 2013 9:27 AM