title: WCF - IMetadataExchange could not be found in the list of contracts implemented by the service
body: <p>I'v been attempting to configure my WCF service to expose both SOAP and Json endpoints. However in doing so I seem to have broken my MEX endpoint with the error:</p>
  
  <blockquote>
    <p>System.InvalidOperationException: The contract name 'IMetadataExchange' could not be found in the list of contracts implemented by the service TestService.  Add a ServiceMetadataBehavior to the configuration file or to the ServiceHost directly to enable support for this contract.</p>
  </blockquote>
  
  <pre><code>  &lt;configuration&gt;
    &lt;system.web&gt;
      &lt;compilation debug="true"/&gt;
    &lt;/system.web&gt;
    &lt;!-- When deploying the service library project, the content of the config file must be added to the host's 
    app.config file. System.Configuration does not support config files for libraries. --&gt;
    &lt;system.serviceModel&gt;
      &lt;bindings&gt;
        &lt;basicHttpBinding&gt;
          &lt;binding name ="soapBinding"&gt;
            &lt;security mode="None"/&gt;
          &lt;/binding&gt;
        &lt;/basicHttpBinding&gt;
        &lt;webHttpBinding&gt;
          &lt;binding name="webBinding"/&gt;
        &lt;/webHttpBinding&gt;
        &lt;mexHttpBinding&gt;
          &lt;binding name="mexBinding"/&gt;
        &lt;/mexHttpBinding&gt;
      &lt;/bindings&gt;
      &lt;behaviors&gt;
        &lt;endpointBehaviors&gt;
          &lt;behavior name="poxBehavior"&gt;
            &lt;webHttp/&gt;
          &lt;/behavior&gt;
          &lt;behavior name="jsonBehavior"&gt;
            &lt;enableWebScript  /&gt;
          &lt;/behavior&gt;
        &lt;/endpointBehaviors&gt;
        &lt;serviceBehaviors&gt;
          &lt;behavior name="defaultBehavior"&gt;
            &lt;serviceDebug includeExceptionDetailInFaults="true" /&gt;
            &lt;serviceMetadata httpGetEnabled="true" /&gt;
          &lt;/behavior&gt;
        &lt;/serviceBehaviors&gt;
      &lt;/behaviors&gt;
      &lt;services&gt;
        &lt;service name="TVD_WCF_Services.TestService" behaviorConfiguration="defaultBehavior"&gt;
          &lt;host&gt;
            &lt;baseAddresses&gt;
              &lt;!-- note, choose an available port--&gt;
              &lt;add baseAddress="http://localhost:8732/Design_Time_Addresses/TVD_WCF_Services/TestService/" /&gt;
            &lt;/baseAddresses&gt;
          &lt;/host&gt;
          &lt;endpoint address="soap" binding="basicHttpBinding" bindingConfiguration="soapBinding" contract="TVD_WCF_Services.ITestService" /&gt;
          &lt;endpoint address="pox" binding="webHttpBinding" bindingConfiguration="webBinding" behaviorConfiguration="poxBehavior" contract="TVD_WCF_Services.ITestService" /&gt;
          &lt;endpoint address="json" binding="webHttpBinding" bindingConfiguration="webBinding" behaviorConfiguration="jsonBehavior" contract="TVD_WCF_Services.ITestService" /&gt;
          &lt;endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="mexBinding" contract="IMetadataExchange" /&gt;
        &lt;/service&gt;
      &lt;/services&gt;
    &lt;/system.serviceModel&gt;
  
    &lt;startup&gt;
      &lt;supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/&gt;
    &lt;/startup&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>I'm sure there is something wrong with the config but for the life of me I cannot work out what it is. Note that I have not changed anything other than the App.config so far so I'm sure the problem lies within.</p>
  
  <p>I've looked at the various other questions related to this on the site but to no avail.</p>
  
  <p>Any WCF gurus out there that can help?</p>