I have a WCF service(maybe multiple services) and a client in Silverlight(C#). As I read somewhere on the web F# is great for async and parallel programming. I want to give F# a try and write a library that communicates to given WCF service, handles it’s faults and returns result.
Are there any benefits of doing so, except learning new language and func programming?
I have a WCF service(maybe multiple services) and a client in Silverlight(C#). As I
Share
Yes, I think F# can be quite useful for asynchronous programming in this scenario. If you want to write your asynchronous code properly, you need to use
BeginFoo/EndFoomethods or you need to use event-based API to avoid blocking the UI thread when performing some asynchronous call. As a result, you cannot write code in the usual sequential style – just by doing one operation after another. Instead, you need to wrap everything in callbacks that contain separate exception handling.In F#, you can use asynchrornous workflow that hide all the “callbacks” and automaticaly wrap everything in exception handlers. As a result, you can write asynchronous code that does multiple calls as a sequential code and use all usual control flow constructs (such as
try,for,while, …). You can write:This calls the
DoSomethingoperation asynchronously and moves the rest of the function into a callback that gets executed when the operation completes (and similarly forDoSomethingElse). However, the exception handling can be written in the usual way. The feature is also nice for writing some user interface interactions (see for example this SO post or the recording of my F# talk at London User Group)The disadvantage of using F# for this project that it doesn’t have any direct support for WCF. You can certainly use it, but you’ll have to write C#-style mutable classes, which doesn’t look that nice – a good option may be to use a C# library and define the usual necessary WCF stuff there (and then just use it from F#).