0

I have read numerous different things about WCF in C#, but still haven't found a satisfactory answer to my noopy problem, yet. (I'm new to C# and .NET)

When i run my selfhosted WCF Service inside VS everything works fine. It also works fine when I run the generated exe-file (clientdir\bin\debug\consoleApp.exe) of my client application while VS is running. However, when I run the generated exe-file(s) (clientdir\bin\debug\consoleApp.exe and hostdir\bin\debug\consoleApp.exe) while VS is not running, I get an EndpointNotFoundException.

Here's the App.config of my client application:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_ImyService" />
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:1592/myService.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ImyService"
                contract="refmy.ImyService" name="BasicHttpBinding_ImyService" />
        </client>
    </system.serviceModel>
</configuration>

And here's the App.config of my host application:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="MetadataBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDiscovery />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service behaviorConfiguration="MetadataBehavior" name="my.myService">
        <endpoint binding="basicHttpBinding" bindingConfiguration="" name="httpEndpoint" contract="my.ImyService" />
        <endpoint binding="netTcpBinding" bindingConfiguration="" name="netTcpEndpoint" contract="my.ImyService" />
        <endpoint address="MEX" binding="mexTcpBinding" bindingConfiguration="" name="mexEndpoint" contract="IMetadataExchange" />
        <endpoint name="udpDiscovery" kind="udpDiscoveryEndpoint" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:9400/myService" />
            <add baseAddress="net.tcp://localhost:9500/myService" />
          </baseAddresses>
        </host>
      </service>
    </services>
  </system.serviceModel>
</configuration>

This is the C# code of my host application:

using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;
using my;

namespace myHost
{
    class Program
    {
        static void Main(string[] args)
        {
            ServiceHost host = new ServiceHost(typeof(myService));
            host.Open();
            Console.ReadLine();

        }
    }
}
Boozzz
  • 245
  • 1
  • 6
  • 19
  • Have you tried using your local ip address instead of localhost? – Louis van Tonder Jun 12 '14 at 09:47
  • Thank you for the reply! Changing `localhost` to my local IP, which is `192.168.167.61`, does not solve my problem. Now, even when I debug the code in VS I get the EndpointNotFoundException. – Boozzz Jun 12 '14 at 10:33

2 Answers2

1

You have invalid endpoint address in client config. It should be as:

address="http://localhost:9400/myService"
Uriil
  • 11,948
  • 11
  • 47
  • 68
  • 1
    I don't think this is correct. `httpEndpoint` is the configuration name for the endpoint, not the address. If the endpoint had `httpEndpoint` as the address (` – Tim Jun 12 '14 at 09:49
0

Your client address doesn't match the service address:

<client>
        <endpoint address="http://localhost:1592/myService.svc"

Service:

<add baseAddress="http://localhost:9400/myService" />

Try using:

<client>
    <endpoint address="http://localhost:9400/myService".....
Tim
  • 28,212
  • 8
  • 63
  • 76
  • Thank you for the reply! When I change the port from 1592 to 9400 does not solve my problem. Now, even when I debug the code in VS I get the EndpointNotFoundException. – Boozzz Jun 12 '14 at 10:18
  • Did you change `myService.svc` to `myService` as well (drop the .svc extension)? – Tim Jun 12 '14 at 10:20
  • Actually, I only renamed `myService.svc` to `myService`, but I have **not** renamed `myService.svc.cs` to `myService.cs`. Should I? – Boozzz Jun 12 '14 at 10:29
  • Depends on whether the markup in myService.svc refers to myService.svc.cs or not. – Tim Jun 12 '14 at 10:47
  • My example originates from a textbook. Just now, I tested the original code from the textbook and I get the same errors. I'm not sure if it's possible that the code from the textbook has errors. Could my VS settings be the problem? Is there a way to provide you with my project code (upload or email)? – Boozzz Jun 12 '14 at 11:34