IMetadataExchange MEX endpoint error when hosting WCF service in console application

Matt picture Matt · Aug 21, 2009 · Viewed 17k times · Source

I have a WCF service. I am trying to host the service in a console application.

I am following all the directions here.

Now everything compiles fine, but I get an exception at runtime.

The contract name 'IMetadataExchange' could not be found in the list of contracts implemented by the service Indexer. Add a ServiceMetadataBehavior to the configuration file or to the ServiceHost directly to enable support for this contract.

Now in the directions, I am instructed to add

<endpoint binding="mexHttpBinding" bindingConfiguration=""
name="http://localhost:8080/myservice/MEX/" contract="IMetadataExchange" />

I don't have IMetadataExchange anywhere in my WCF service or the host console application.

Where does the exception come from? Is there a reference I am missing?

This is my console program

namespace WcfConsoleHost
{
    class Program
    {
        static void Main(string[] args)
        {
            Type type = typeof(myservice);
            using (ServiceHost host = new ServiceHost(type))
            {

                host.Open();
                Console.WriteLine("The service is available. Press any key...");
                Console.ReadKey();
                host.Close();
            }
        }
    }
}

My WCF service just has an Interface with the contracts and then the implemetation in the myservice class.

Below is my entire app.config.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <behaviors>
            <serviceBehaviors>
                <behavior name="ServiceBehavior">
                    <serviceMetadata />
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <services>
            <service name="myservice">
                <endpoint address="http://localhost:8080/myservice/"
                 binding="basicHttpBinding"
                    bindingConfiguration="" contract="myservice.Ims" />
                <endpoint binding="mexHttpBinding" bindingConfiguration=""
                 address="http://localhost:8080/myservice/MEX/"
                    contract="IMetadataExchange" />
            </service>
        </services>
    </system.serviceModel>
</configuration>

Answer

tomasr picture tomasr · Aug 21, 2009

The mex endpoint has the wrong attribute for the address... it should be address, not name.