Windows service (WCF service hosting) stops immediately upon startup

My question is: I can’t go to the base address after installing the service, because the service will not work (it stops immediately). Is there anything I need to do on the server or my machine to make baseAddress valid?

Reference Information. I am trying to learn how to use WCF services hosted on Windows services. I read a few tutorials on how to do this, and it seems very straightforward. I looked through this article on an MSDN article and built it step by step. I can install the service on my computer and on the server, but when I start the service, it stops immediately. Then I found this tutorial , which is essentially the same, but contains some clients that consume the WCF service. I downloaded the source code, compiled, installed, but when I started the service, it immediately stopped.

Searching for SO, I found a possible solution that says to determine baseAddress when creating an instance of ServiceHost, but that didn't help either.

My serviceHost is defined as:

serviceHost = new ServiceHost( typeof( CalculatorService ), new Uri( "http://localhost:8000/ServiceModelSamples/service" ) ); 

My service name, base address, and endpoint:

 <service name="Microsoft.ServiceModel.Samples.CalculatorService" behaviorConfiguration="CalculatorServiceBehavior"> <host> <baseAddresses> <add baseAddress="http://localhost:8000/ServiceModelSamples/service"/> </baseAddresses> </host> <endpoint address="" binding="wsHttpBinding" contract="Microsoft.ServiceModel.Samples.ICalculator"/> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> </service> 

I verified that the namespaces are identical. It just disappoints that the tutorials assume that the Windows service will start while all of the above steps are followed. I'm missing something, and it's probably right in front of me. Please, help!

+4
source share
3 answers

When your Windows service stops immediately, an exception is thrown in the OnStart method. Try to catch and register this exception.

+8
source

I had a similar problem when trying to start a service in which WCF with overloaded methods or optional parameters and C # compilers without any errors but not allowed in WCF ...

+1
source

Later, but I find this line the first line in OnStart extremely useful in debugging services:

 System.Diagnostics.Debugger.Launch(); 

Then you can select the current Visual Studio session with the already loaded project (note: you may need to run this as an administrator) and start executing your code.

+1
source

Source: https://habr.com/ru/post/1333800/


All Articles