Search code examples
.netwcfwcf-data-servicesodata

how can I add an ipfilter to an wcf odata service


How can I add an IP filter to my oData WCF service?

I found some blog posts which explain to do it adding extra configuration in the web.config, only I have nothing in the web.config (about the service).

I followed Hanselmans example on how to add an oData feed, which doesn't involve configuring wcf via the web.config.


Solution

  • The way WCF 4 works is that if the value is default it does not need to be there. So if you do not individually configure your services you need to change the default service behaviour.

    You can do it by configuring the service behaviour, for example:

    <configuration>
     <system.serviceModel>
      <behaviors>
      <serviceBehaviors>
        <behavior> <!-- notice no name attribute -->
         <serviceMetadata httpGetEnabled="true" /> 
         <serviceDebug includeExceptionDetailInFaults="true" /> 
         <IPFilter filter="172.*.*.* 127.0.0.1" />           
        </behavior>
       </serviceBehaviors>
       </behaviors>
     </system.serviceModel>
    </configuration>