13

I know this has been asked many times, and answered many times, but, all the provided samples that should be working don't seem to want to work for me today.

When I try to start the host, I keep getting the following error:

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

My service is being hosted in a managed windows service host as per Microsoft's example: http://msdn.microsoft.com/en-us/library/ms733069%28v=vs.90%29.aspx

And here is my nice and simple config:

  <system.serviceModel>
    <services>
      <service name="Daff.Lae.Service.TraceService">
        <endpoint address="" binding="wsHttpBinding" name="TraceService" contract="Contracts.Service.ITraceService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8080/TraceService" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="DefaultBehavior">
          <serviceDebug includeExceptionDetailInFaults="true"/>
          <serviceMetadata httpGetEnabled="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

Of course, the problem becomes more interesting when there are no errors if I remove this line:

<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>

Any help would be very very very greatly appreciated :)

agAus
  • 675
  • 1
  • 7
  • 11

3 Answers3

25

Be sure to specify a behaviorConfiguration in the service element of your configuration in order to allow either httpGet or httpsGet.

I see that you have already defined a serviceBehavior named DefaultBehavior - now all you need to do is add behaviorConfiguration="DefaultBehavior" to the service element, so that line becomes:

<service name="Daff.Lae.Service.TraceService" behaviorConfiguration="DefaultBehavior">

If you don't explicitly specify a behavior for your service, both HTTP GETs and HTTPS GETs are disallowed by default, and your metadata will not be exposed.

RoccoC5
  • 4,185
  • 16
  • 20
2

As you're using WS-Http you are binding to an HTTPS protocol, so you need to use the correct MEX binding;

<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" /> 

and change the baseaddress to a https one.

Or (the other way around) convert your wsHttp binding to a basicHttp binding and things will start working for you.

kroonwijk
  • 8,340
  • 3
  • 31
  • 52
  • Ahh...I didn't realise wsHttpBinding meant it was https? I'm tied up with a prod release today but would definitely like to try this and get back to you. I have bookmarked my question so I can update the post accordingly. Thanks :) – agAus Sep 21 '11 at 06:02
0
`<services>
  <service  name="MyService.Service1" behaviorConfiguration="Service1" >

</services>
 `

 where MyService is the application name , Service1 is the default implementation class for IService1
 `
 <protocolMapping>
  //Remove any http or https bindings provided  
</protocolMapping>   
 `
It should help when you use WCF Application Project
Joe
  • 509
  • 4
  • 11