How to configure WCF REST service hosted in IIS (properly)?
Trying to configure WCF REST service hosted in IIS you may encounter an error message saying something like:
"The message with To '*' cannot be processed at the receiver, due to an AddressFilter mismatch at the EndpointDispatcher. Check that the sender and receiver's EndpointAddresses agree."
where '*' is the address you are trying to access. There are some answers here and there on the web but those are incomplete or hard to understand.
The Problem
When using the "*.svc" file to host a service within ASP.NET web site, regular WCF ServiceHost is created. WCF itself does not understand the REST address (as specified by the UriTemplate property of WebGet attribute), so we should configure the proper endpoint behavior "webHttp".
The Solution
So, here is how to configure WCF REST service to be hosted in IIS:
To host a service on IIS we are creating ".svc" file to map that file URL to the service type, for example:
<%@ ServiceHost Language="C#" Debug="true" Service="[ServiceFullTypeName]" %>
To enable this service as REST service, we will configure the required endpoint and behaviors in web.config:
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="WebBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service name="[ServiceTypeFullName]">
<endpoint address="js" binding="webHttpBinding" behaviorConfiguration="WebBehavior" contract="[ServiceContractName]"/>
</service>
</services>
</system.serviceModel>
Thats all!
Note that the "baseAddress" of this service is the URL to the ".svc" file, the "js" address is not required, but I prefer to distinguish between the "regular" address and the JSON address.