I have the following code, that I am testing...
public static void Main()
{
try
{
ServiceHost host = null;
host = new ServiceHost(typeof(StockService), new Uri("http://localhost:8080/EssentialWCF"));
host.AddServiceEndpoint(typeof(IStockService),new BasicHttpBinding(), "");
ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
behavior.HttpGetEnabled = true;
host.Description.Behaviors.Add(behavior);
host.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(), "mex");
host.Open();
Console.WriteLine("Host opened. Waiting...");
Console.Read();
host.Close();
}
catch(Exception e)
{
Console.WriteLine(e.Message);
Console.Read();
}
}
I am able to open the Host and listen on the port but if I switch the lines like this...
public static void Main()
{
try
{
ServiceHost host = null;
host = new ServiceHost(typeof(StockService), new Uri("http://localhost:8080/EssentialWCF"));
host.AddServiceEndpoint(typeof(IStockService),new BasicHttpBinding(), "");
host.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(), "mex");
ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
behavior.HttpGetEnabled = true;
host.Description.Behaviors.Add(behavior);
host.Open();
Console.WriteLine("Host opened. Waiting...");
Console.Read();
host.Close();
}
catch(Exception e)
{
Console.WriteLine(e.Message);
Console.Read();
}
}
Basically, define the Service end point for Mex first and then add the service behavior, I get the following exception with the message
The contract name 'IMetadataExchange' could not be found in the list of contract s implemented by the service EssentialWCF.StockService. Add a ServiceMetadataBe havior to the configuration file or to the ServiceHost directly to enable suppor t for this contract.
what is the dependency that I have to define them in the correct order...??
Thanks Harsha