I want to create WCF service and host it via Windows service.
I have created everything according to tutorial https://msdn.microsoft.com/en-us/library/ff649818.aspx
Here is my WCF services library
App.config. I have changed it for using TCP protocol
<system.serviceModel>
<services>
<service name="WCFServiceLibrary.Service1">
<endpoint address="" binding="netTcpBinding" bindingConfiguration=""
contract="WCFServiceLibrary.IService1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:3000/Service1" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Then I copied the App.config to the WindowsService project. I also added the installer of WindowsService and then I changed the properties:
StartType - Automatic
Account - NetWorkService
Then I built this project and
successfully installed it using the Installutil WindowsService.exe
But then, when I'm trying to add the service (net.tcp://localhost:3000/Service1) reference in my WPFClientProject
it appears:
The URI prefix is not recognized. Metadata contains a reference that cannot be resolved: 'net.tcp://localhost:3000/Service1'. Could not connect to net.tcp://localhost:3000/Service1. The connection attempt lasted for a time span of 00:00:02.0641450. TCP error code 10061:
It looks like i do not have a host. What am I doing wrong?
Windows Service code
public partial class Service1: ServiceBase
{
internal static ServiceHost myServiceHost = null;
public Service1()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
if (myServiceHost != null)
{
myServiceHost.Close();
}
myServiceHost = new ServiceHost(typeof(Service1));
myServiceHost.Open();
}
protected override void OnStop()
{
if (myServiceHost != null)
{
myServiceHost.Close();
myServiceHost = null;
}
}
}