none
Can't correct the error in this basic WCF Service hosted in a Console Application RRS feed

  • Question

  • I have a basic WCF Service hosted in a Console Application that I can't consume from another Console Application.

    I'm studying WCF so I'm trying to make it work to follow along with a book.

    When I try to consume the service I get the following error "Unhandled Exception: System.ServiceModel.EndpointNotFoundException: There was no endpoint listening at http://localhost:6599/HostCmdLineApp/HelloWorldService.svc/HelloWorldService that could accept the message. This is often caused by an incorrect address or SOAP action..."

    But the service runs well:

    I'm using VS2012.

    The general structure of the solution is:

    HelloWorldService is the service, HostCmdLineApp hosts the service and HelloWorldClient consumes it.

    In HostCmdLineApp (the service Host), the service is described in the App.config file with:

    <system.serviceModel>
        <services>
            <service name="MyWCFServices.HelloWorldService"
                        behaviorConfiguration="HelloWorldServiceBehavior">
                <endpoint address="HelloWorldService"
                            binding="basicHttpBinding"
                            contract="MyWCFServices.IHelloWorldService" />
    
                <endpoint address="mex"
                            binding="mexHttpBinding"
                            contract="IMetadataExchange" />
            </service>
        </services>
        <behaviors>
            <serviceBehaviors>
                <behavior name="HelloWorldServiceBehavior">
                    <serviceMetadata httpGetEnabled="true"/>
                </behavior>
            </serviceBehaviors>
        </behaviors>
    </system.serviceModel>

    The Main method that publishes the service from HostCmdLineApp is:

    static void Main(string[] args) {
        var baseAddress = new Uri("http://localhost:6599/HostCmdLineApp/HelloWorldService.svc");
        using (var host = new ServiceHost(typeof(MyWCFServices.HelloWorldService), baseAddress)) {
            host.Open();
            Console.WriteLine("HelloWorldService is ready to be used. ");
            Console.WriteLine("Press <ENTER> to terminate service.");
            Console.ReadKey();
            host.Close();
        }
    }

    The App.config file of HelloWorldClient (the service consumer) was generated by the SvcUtil tool:

    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IHelloWorldService" />
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:6599/HostCmdLineApp/HelloWorldService.svc/HelloWorldService"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IHelloWorldService"
                contract="IHelloWorldService" name="BasicHttpBinding_IHelloWorldService" />
        </client>
    </system.serviceModel>

    And the Main method that consumes the service is:

    static void Main(string[] args) {
        var client = new HelloWorldServiceClient();
        Console.WriteLine(client.GetMessage("Rafael Soteldo"));
    }

    I ran VS as Administrator.


    Believe you can do it, and you will!!


    Monday, February 24, 2014 10:22 PM

Answers