wcf 4.0 IMetadataExchange contract not found RRS feed

  • Question

  • I am configuring a WCF service in a windows service.

    Here is my code

        private ServiceHost monitorServiceHost = null;
        protected override void OnStart(string[] args)
            if (this.monitorServiceHost != null)
            this.monitorServiceHost = new ServiceHost(typeof(Monitor));

    And here is my app.config file

    <?xml version="1.0" encoding="utf-8" ?>
            <binding name="basicHttpBinding" bypassProxyOnLocal="true" />
            <binding name="mexBinding" />
          <service behaviorConfiguration="MonitorServiceBehavior" name="MyService.Monitor">
            <endpoint binding="basicHttpBinding" bindingConfiguration="basicHttpBinding"
              contract="MyService.IMonitor" />
            <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="mexBinding"
              contract="System.ServiceModel.Description.IMetadataExchange" />
                <add baseAddress="http://localhost:7000/Monitoring/monitor" />
            <behavior name="MonitorServiceBehavior">
              <serviceMetadata httpGetEnabled="true"/>
              <serviceDebug includeExceptionDetailInFaults="true"/>

    When I try to start the service I got runtime error in event viewer that The contract name 'System.ServiceModel.Description.IMetadataExchange' could not be found in the list of contracts implemented by the service 'Monitor'.

    And MSDN sample has similar codes and configs.

    What is wrong with my code?

    Welcome to help me with my open source project at

    Wednesday, January 23, 2013 7:28 PM


  • Hi,

    Please remove the bindingConfiguration for mex endpoint, try

    <endpoint address="mex" binding="mexHttpBinding"
              contract="IMetadataExchange" />

    The service metadata behavior will tell WCF to handle IMetadataExchange contract.

    Best Regards.

    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Hardy Thursday, January 24, 2013 12:48 PM
    Thursday, January 24, 2013 3:27 AM