In my last post, I provided an overview of using the new WebGet attribute to map an HTTP GET operation to a specific method. However, I didn't cover the the necessities for hosting a service that uses this functionality.
If you intend to expose multiple endpoints that use more than one binding, it is necessary to use the traditional approach of ServiceHost. In order for WebGet to work correctly, an endpoint that uses the new binding named WebHttpBinding is required. As usual this can be done programmatically or via configuration. Regardless of the approach that is used, the WebHttpBehavior must be applied to the endpoint that is using the WebHttpBinding. This is a special endpoint behavior that enables the web programming model.
Here is the equivalent via configuration:
If you only intend to use the WebHttpBinding, there is a much easier alternative. There is a specialized implementation of ServiceHost named WebServiceHost that does not require any configuration. You simply specify the service type and the base uri. It will automatically use the WebHttpBinding and WebHttpBehavior.
To use this host in IIS, the following .svc file could be used:
<%@
ServiceHostFactory="System.ServiceModel.Activation.WebServiceHostFactory"
Language="C#"
Service="ServiceApplication.WeatherService"
CodeBehind="~/App_Code/WeatherService.cs" %>