Chris Dunn

Chris Dunn

  • NA
  • 2
  • 5.2k

Problem with Service Endpoint Definition

Dec 16 2012 9:02 AM

I am attempting a .NET Framework 4.5 Getting Started tutorial on WCF. I have created the application in Visual Studio 2012 Ultimate on a Windows 7 Professional 64 bit machine.

The URL to the tutorial step where I am having the issue: http://msdn.microsoft.com/en-us/library/ms730935.aspx

I have followed all four of the steps laid out under 'To create a new console application to host the service'.

When I get down to 'To verify the service is working', I can debug 'GettingStartedHost', and the console window opens. The problem is that if I go to the debug page of

http://localhost:8000/GettingStarted/CalculatorService

I've also tried to modify the URL to use 'GettingStartedHost' and 'GettingStartedLib' instead of 'GettingStarted'.

I get a 404 error that the web page cannot be found. If I bring up the WCF Service Host window, it shows that the GettingStartedLib.CalculatorService has been stopped. When I select the service, 'Additional Information' shows the following:

"The service cannot be started. This service has no endpoint defined. Please add at least one endpoint for the service in config file and try again."

Program.cs has the service endpoint defined in a try/catch like this:

            try
            {
                // Step 3 Add a service endpoint.
                selfHost.AddServiceEndpoint(typeof(ICalculator), new WSHttpBinding(), "CalculatorService");

                // Step 4 Enable metadata exchange.
                ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
                smb.HttpGetEnabled = true;
                selfHost.Description.Behaviors.Add(smb);

                // Step 5 Start the service.
                selfHost.Open();
                Console.WriteLine("The service is ready.");
                Console.WriteLine("Press <ENTER> to terminate service.");
                Console.WriteLine();
                Console.ReadLine();

                // Close the ServiceHostBase to shutdown the service.
                selfHost.Close();
            }
            catch (CommunicationException ce)
            {
                Console.WriteLine("An exception occurred: {0}", ce.Message);
                selfHost.Abort();
            }

Why would there be a problem with the Service Endpoint? The tutorial states that with .NET 4.5 that I don't even need to specify the endpoint.

Thank you for your help.