tags:

views:

58

answers:

1

Hi, On hosting my WCF service called "SimpleWCF" on IIS; I am getting the following error while manually browsing it in my browser;

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


I cannot understand the cause of this error [still new].
Here is my config file;

<configuration>
  <system.serviceModel>
  <behaviors>
  <endpointBehaviors>
    <behavior name="">
     <webHttp />
    </behavior>
  </endpointBehaviors>
  <serviceBehaviors>
    <behavior name="">
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
<bindings>
  <basicHttpBinding>
    <binding name="LargeData" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
      <security mode="None">
      </security>
    </binding>
  </basicHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<services>
  <service name="SimpleWCF">
    <endpoint address="http://localhost/Sample/SimpleWCF.svc" binding="basicHttpBinding" bindingConfiguration="LargeData" contract="SimpleWCF"/>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
  </service>
</services>
  </system.serviceModel>
  <system.web>
<compilation debug="true"/>
  </system.web>
</configuration>
A: 

In your config, you need to give valid names to your behaviors!

<behaviors>
  <endpointBehaviors>
    <behavior name="webBehavior">
     <webHttp />
    </behavior>
  </endpointBehaviors>
  <serviceBehaviors>
    <behavior name="serviceBehavior">
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
  </serviceBehaviors>
</behaviors>

and them from your <service> tag, you need to reference that behavior:

<service name="SimpleWCF" behaviorConfiguration="serviceBehavior">

for it to become active.

If you're on .NET 4 / WCF 4, you can also define default behaviors - but then you need to entirely leave out the name= attribute:

<behaviors>
  <endpointBehaviors>
    <behavior>
     <webHttp />
    </behavior>
  </endpointBehaviors>
  <serviceBehaviors>
    <behavior>
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
  </serviceBehaviors>
</behaviors>

Now each endpoint will get that endpoint behavior, and each service will get the service behavior.

marc_s