Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF MetaData not working

Tags:

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"   %>
like image 340
Program.X Avatar asked May 18 '09 09:05

Program.X


2 Answers

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

like image 128
Brian Avatar answered Nov 12 '22 08:11

Brian


I am using NetTcpBinding for all. In my case I was having the same issue and resolved it by adding:

(a) a behaviorConfiguration="" to the mex endpoint

  <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" behaviourConfiguration="" />

(b) a behaviorConfiguration="mex" to the service definition:

  <services>
     <service name="AcmeService" behaviorConfiguration="mex">

(c) The behaviour entry

  <behaviors>
    <serviceBehaviors>
        <behaviour name="mex">
            <serviceDebug includeExceptionDetailInFaults="false"/>
            <serviceMetadata />
        </behavior>
     </serviceBehaviors>
  </behaviors>
like image 39
Lord of Scripts Avatar answered Nov 12 '22 09:11

Lord of Scripts