My Question: I cannot navigate to the base address once the service is installed because the service won't remain running (stops immediately). Is there anything I need to do on the server or my machine to make the baseAddress valid?
Background: I'm trying to learn how to use WCF services hosted in Windows Services. I have read several tutorials on how to accomplish this and it seems very straight forward. I've looked at this MSDN article and built it step-by-step. I can install the service on my machine and on a server, but when I start the service, it stops immediately. I then found this tutorial, which is essentially the same thing, but it contains some clients that consume the WCF service. I downloaded the source code, compiled, installed, but when I started the service, it stopped immediately.
Searching SO, I found a possible solution that said to define the baseAddress when instantiating the ServiceHost, but that didnt 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've verified the namespaces are identical. It's just getting frustrating that the 开发者_如何学JAVAtutorials seem to assume that the Windows service will start as long as all the stated steps are followed. I'm missing something and it's probably right in front of me. Please help!
When your windows service stops immediately, there is an exception raised in the OnStart method. Please try to catch and log that exception.
Late to this, but I find this line as the first line in OnStart
to be immensely helpful in debugging services:
System.Diagnostics.Debugger.Launch();
You can then select a running session of Visual Studio with your project already loaded (note: you might need to have that running as admin) and start stepping through your code.
I used to have similar problem when trying to start a service that hosts WCF with overloaded methods or optional parameters and compiles in C# without any errors but are not allowed in WCF...
精彩评论