WCF MetaData not working

wcf

I have tried several times to have my WCF service expose MetaData. Instead, I keep keeping the exception:

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

… when manually browsing to the service using IE.

(I am presuming this is the same reason why my client application isn't able to generate a service reference. Baby steps and all)

And yet my web.config looks okay:

<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<behaviors>
    <endpointBehaviors>
        <behavior name="webHttpEnablingBehaviour">
            <webHttp />
        </behavior>
    </endpointBehaviors>
    <serviceBehaviors>
        <behavior name="webHttpEnablingBehaviour">
            <serviceMetadata httpGetEnabled="true" />
        </behavior>
    </serviceBehaviors>
</behaviors>
<services>
    <service name="IWW.MIGTurbo2.WCF.Security.SecurityBroker">
        <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
        <endpoint address=""
            binding="webHttpBinding"
            bindingConfiguration="default"
            contract="IWW.MIGTurbo2.WCF.Security.ISecurityBroker"
                behaviorConfiguration="webHttpEnablingBehaviour">
        </endpoint>
    </service>
</services>
<client />
<bindings>
    <webHttpBinding>
        <binding name="default" />
    </webHttpBinding>
</bindings>
</system.serviceModel>

So I have my IMetadataExchange contract defined with mex fine, and hooked up, as far as I can see. Have I missed something daft?

Edit

My Service definition is shown below, if this is useful:

<%@ ServiceHost Language="C#" Debug="true" Service="IWW.MIGTurbo2.WCF.Security.SecurityBroker" Factory="System.ServiceModel.Activation.WebScriptServiceHostFactory"   %>

Best Answer

Your config file has the behaviorConfiguration attribute on the "endpoint" element, but you also need it on the "service" element.

Related Topic