Q:

WCF Service(NetTcpBinding) + host on managed WPF application

I want to create a WPF application with WCF Service to listen on some port. I create C# CLass Library(UfebsSignServiceLibrary) and added inside the WCF Service. After in library I added interface and class implementer.
I created WPF application and want to host my WCF Service inside. I added reference to UfebsSignServiceLibrary in my WPF APP, configuration app.config. WPF started, but when i try add Service Reference on my WCF Service I get an error - metadata contains a reference that cannot be resolved.
I already tried enable "httpGetEnabled", "httpsGetEnabled" and added baseAddress for http protocol (). I read many topics about same problem, but i don't finded answer for my situation. 
My Class Library with WCF Service code:

namespace UfebsSignServiceLibrary
    {
        [ServiceContract]
        public interface IUfebsSignService
        {
            [OperationContract]
            byte[] SignData(byte[] data, string profileName);
        }

namespace UfebsSignServiceLibrary
{
    public class UfebsSignService : IUfebsSignService
    {
        public byte[] SignData(byte[] data, string profileName)
        {
            // Some Code
        }
    }

My WPF APP code:

public MainWindow()
        {
            InitializeComponent();
            DataContext = this;
        }

        private void Start_Click(object sender, RoutedEventArgs e)
        {
                using (host = new ServiceHost(typeof(UfebsSignService)))
                {
                    host.Open();
                }

                Stop.IsEnabled = true;
                Start.IsEnabled = false; 
        }

        private void Stop_Click(object sender, RoutedEventArgs e)
        {
            host.Close();
            Stop.IsEnabled = false;
            Start.IsEnabled = true;
        }

App.config code(wpf app):

<system.serviceModel>

    <behaviors>
      <serviceBehaviors>
        <behavior name="mexBehavior">
          <serviceMetadata  /> <!--httpGetEnabled="false"-->
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service behaviorConfiguration="mexBehavior" name="UfebsSignServiceLibrary.UfebsSignService">
        <host>
          <baseAddresses>
            <!--<add baseAddress="http://localhost:8080/UfebsSignService" />-->
            <add baseAddress="net.tcp://localhost:8585/UfebsSignService/" />
          </baseAddresses>
        </host>
        <endpoint address="" binding="netTcpBinding" contract="UfebsSignServiceLibrary.IUfebsSignService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />   
      </service>
    </services>
  </system.serviceModel>

The URI prefix is not recognized.
  Metadata contains a reference that cannot be resolved: 'net.tcp://localhost:8585/UfebsSignService/'.
  Could not connect to net.tcp://localhost:8585/UfebsSignService/. The connection attempt lasted for a time span of 00:00:02.0140574. TCP error code 10061

A:

There is a small problem in the code snippets. When we use USING statement, it will automatically release the managed resources. Please consider using the below code to start the service host.
host = new ServiceHost(service);
host.Open();

Feel free to let me know if the problem still exists.

