Monday, June 18, 2012

The contract name 'IMetadataExchange' could not be found in the list of contracts implemented by the service


The contract name 'IMetadataExchange' could not be found in the list of contracts implemented by the service HelloWorld.  Add a ServiceMetadataBehavior to the configuration file or to the ServiceHost directly to enable support for this contract.
This error occurs when we define a servicebehavior and did not attach the behavior to the service name configuration.
If your configuration looks like below and when you try to run the host, you will get the error specified above.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
      <system.serviceModel>
            <services>
                  <service name="HelloWorldService.HelloWorld">
                        <endpoint contract="HelloWorldService.IHelloWorld" address="HelloWorld" binding="basicHttpBinding"></endpoint>
                        <endpoint contract="IMetadataExchange" address="Mex" binding="mexHttpBinding"></endpoint>
                        <host>
                              <baseAddresses>
                                    <add baseAddress="http://localhost:8000"/>
                              </baseAddresses>
                        </host>
                  </service>
            </services>
            <behaviors>
                  <serviceBehaviors>
                        <behavior name="MyServiceBehavior">
                              <serviceMetadata httpGetEnabled="true"/>
                        </behavior>
                  </serviceBehaviors>
            </behaviors>
      </system.serviceModel>
</configuration>
The solution is as below in this case (Add the behaviorConfiguration in the service section):
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
      <system.serviceModel>
            <services>
                  <service name="HelloWorldService.HelloWorld" behaviorConfiguration="MyServiceBehavior">
                        <endpoint contract="HelloWorldService.IHelloWorld" address="HelloWorld" binding="basicHttpBinding"></endpoint>
                        <endpoint contract="IMetadataExchange" address="Mex" binding="mexHttpBinding"></endpoint>
                        <host>
                              <baseAddresses>
                                    <add baseAddress="http://localhost:8000"/>
                              </baseAddresses>
                        </host>
                  </service>
            </services>
            <behaviors>
                  <serviceBehaviors>
                        <behavior name="MyServiceBehavior">
                              <serviceMetadata httpGetEnabled="true"/>
                        </behavior>
                  </serviceBehaviors>
            </behaviors>
      </system.serviceModel>
</configuration>

7 comments:

Anonymous said...

A very good article.. it solved my problem

Anonymous said...

thank u so much ... u r the one ;-)

Anonymous said...

good answer

Anonymous said...

Thank you !!

Anonymous said...

Also solved my problem. Thank you.

Akki said...

Good to know and thanks for visiting...

Anonymous said...

Much thanks man for helping on this niggle.

Post a Comment