Mohamed Ahmed Mohamed Ahmed - 1 month ago 7x
C# Question

WCF service not opening in the browser?

I'm learning WCF, I started creating a very basic host app which defines a class with one method as follows:

public interface IMath
int Add(int a, int b);
public class MathCalcs : IMath
public MathCalcs()
Console.WriteLine("Service await two numbers...");
public int Add(int a, int b)
return a + b;

and that is how I configured the App.config file:

<?xml version="1.0" encoding="utf-8" ?>
<service name="ConsoleHost.MathCalcs" behaviorConfiguration="MathServiceMEXBehavior">
<endpoint address="http://localhost:8080/MathCalcs"
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<add baseAddress="http://localhost:8080/MathCalcs"/>
<behavior name="MathServiceMEXBehavior">
<serviceMetadata httpGetEnabled="true"/>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />

Then I called the service from

using (ServiceHost host = new ServiceHost(typeof(MathCalcs)))
Console.WriteLine("***The service is ready***");

But it fails to view the metadata of the service through the URI http://localhost:8080/MathCalcs, I'm sure I'm following the steps right as the book I'm reading from and as a preceding example works fine, the only difference is that I didn't separate the service logic (the interface and the class) in a stand alone class library.
What am I missing?


The following line of code


must be inside the braces of the using clause! When that is done, retry finding the WSDL metadata.