0

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;
        }
    }
}
Hexray
  • 51
  • 1
  • 3
  • Is the Windows Service running when you try to add the service reference? Have you verified that there is something listening on port 3000? Can you post the windows service code where you start the service host? – Tim May 11 '16 at 01:20
  • My WCF Client placed in another solution. Maybe it is the reason of that problem? I will add the Windows Service code. – Hexray May 11 '16 at 05:55
  • my personal preference is to configure WCF from code, I feel better control while typing and executing too. – Jacek Cz May 11 '16 at 08:49

1 Answers1

0

I had the same issue as you following the tutorial.

I solve it verifing that the windows service is running, it wasn't running because of login credentials. I changed windows service credentials to local system account and it works.

Tuto
  • 36
  • 5