Sunday, March 20, 2011

WCF Basic Authentication:Security settings for this service require 'Anonymous' Authentication but it is not enabled for the IIS application that hosts this service.

I was testing the service to authenticate users with basic authentication over http (not https). To Achieve this, I used basicHttpBinding as binding and configured it for TransportClientCredentialOnly security mode.

<binding name="http_transport_basic">
<security mode="TransportCredentialOnly">
<transport clientCredentialType ="Basic"/>

Everything was looking good so far until I hit the f5 to visit the familiar yellow error page complaining about InvalidMexHttpPoint

But why. I am using basic authentication and basic authentication is enabled in the IIS. Thanx to the Mapelli for the post which points the cause of the problem. I removed the mex point and hit F5 again. There is no more error page. But now the question arises, Is there any way to include the mex point?. Answer is yes. I just replaced the mex binding from  “mexHttpBinding” to basicHttpBinding and created the bindingConfiguration similar to the service endpoint’s binding configuration. This change enabled me to use the mex point which is also configured for basic authentication.

WCF Error: The contract name ‘IMetadataExchange’ could not be found in the list of contracts implemented by the service

This is the most common error almost everyone receives when starts learning WCF and mostly because you have overlooked the configuration. It is easy to miss the typo mistake and specially when it is just matter of lower or upper case of a single character. We, developers, are normally used to capitalize the “D” of the “Data” and this is what we do with “IMetadataExchange” and type “IMetaDataExchange”. Remember configuration parser is case sensitive and it treats “IMetadataExchange” and “IMetaDataExchange” differently. WCF complains this typo mistake in this fashion.spelled wrong

This error clearly states that it is unable to find the contract. Now even after correcting the mistake you still can face another yellow screen of error


This happens because

  • You have not defined serviceMetadata behavior. Go to configuration file and add following configuration sample.
    <behavior name="default">
    <serviceMetadata httpGetEnabled="true" />

  • You have defined the service behavior but have not set the service behavior configuration name. Set the behaviorConfiguration attribute of the service to the name of the service behavior you defined.
<service name="Service" behaviorConfiguration ="default">