Monday, November 15, 2010

Consuming OData Feed from F#

Sadly, there is no tooling around generating an OData service proxy in F# (that I know of).
In order to work around it I created a new C# class library project and used C# to generate a service proxy to any OData feed. I decided to use and Nerd as examples. Once I had the proxies
in C# I built an ODataServiceProxies.dll and referenced it in a F# script file.

#r @"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.ServiceModel.dll"
#r @"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Data.Services.dll"
#r @"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Data.Services.Client.dll"
#r @"D:\ODev Solutions\ODataServices\ODataServiceProxies\bin\Debug\ODataServiceProxies.dll"

open System
open System
open System.Linq
open System.Reflection
open System.Collections
open System.ServiceModel
open System.ServiceModel.Syndication
open System.Xml
open System.Collections.Generic
open System.Data.Services
open ODataServiceProxies.NerdDinner
open ODataServiceProxies.NetflixCatalog
open System.ServiceModel.Activation
let netflix = new NetflixCatalog(new Uri(""))
(*Showing some movie titles from netflix feed*)
    |> Seq.iter(fun t -> printfn "%s" t.Name)

(*Showing some nerd dinners from feed*)
let nerddinner = new NerdDinnerEntities(new Uri(""))
    |> Seq.iter(fun d -> printfn "%s" d.Description)

Very Cool!! I love F#!

No comments:

Post a Comment