none
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.Close();
            }
            this.monitorServiceHost = new ServiceHost(typeof(Monitor));
            this.monitorServiceHost.Open();
        }


    And here is my app.config file

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <system.serviceModel>
        <bindings>
          <basicHttpBinding>
            <binding name="basicHttpBinding" bypassProxyOnLocal="true" />
          </basicHttpBinding>
          <mexHttpBinding>
            <binding name="mexBinding" />
          </mexHttpBinding>
        </bindings>
        <services>
          <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" />
            <host>
              <baseAddresses>
                <add baseAddress="http://localhost:7000/Monitoring/monitor" />
              </baseAddresses>
            </host>
          </service>
        </services>
        <behaviors>
          <serviceBehaviors>
            <behavior name="MonitorServiceBehavior">
              <serviceMetadata httpGetEnabled="true"/>
              <serviceDebug includeExceptionDetailInFaults="true"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>
      </system.serviceModel>
    </configuration>

    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 http://msdn.microsoft.com/en-us/library/ms733069(v=vs.100).aspx has similar codes and configs.

    What is wrong with my code?


    Welcome to help me with my open source project at http://code.google.com/p/batch-image-watermark-processor/

    Wednesday, January 23, 2013 7:28 PM

Answers

  • 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.


    Haixia
    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
    Moderator