{"id":1231,"date":"2012-12-11T09:09:16","date_gmt":"2012-12-11T09:09:16","guid":{"rendered":"http:\/\/www.navision-blog.de\/?p=1231"},"modified":"2012-12-11T15:35:42","modified_gmt":"2012-12-11T15:35:42","slug":"using-footloose-from-fsharp-part-i","status":"publish","type":"post","link":"http:\/\/www.navision-blog.de\/blog\/2012\/12\/11\/using-footloose-from-fsharp-part-i\/","title":{"rendered":"Using Footloose from F# &ndash; part I &ndash; Setting up the infrastructure"},"content":{"rendered":"<blockquote>\n<p>\u201cFootloose is a fast and scalable asynchronous distributed computing and service library that was designed to be secure, simple to use, unobtrusive and without the need of client side code generation or proxy classes. <\/p>\n<p>It was developed to connect or build distributed applications on the .NET\/Mono platform with enterprise features like <strong>load-balancing<\/strong>,<strong> clustering<\/strong>, <strong>encryption<\/strong>, <strong>service discovery<\/strong> and <strong>single-sign on<\/strong>. <\/p>\n<p>Footloose enables you to easily transmit any kind of data between the components of your application over thread-, process- or physical boundaries. Depending on your needs Footloose uses one if its transport channels, e.g. a Named Pipe or a Unix Socket for Inter Process Communication (IPC), AMQP with one of the available Message Broker implementations (like RabbitMQ) in the local network or even <strong>XMPP<\/strong> as a secure and fast realtime messaging protocol that enables you to build cloud services.\u201d<\/p>\n<p align=\"right\"><a href=\"http:\/\/www.footloose-project.de\/about\/\">http:\/\/www.footloose-project.de<\/a><\/p>\n<\/blockquote>\n<p>If you don\u2019t like WCF then you should really check out <a href=\"http:\/\/www.footloose-project.de\">Footloose<\/a>.     <br \/><a href=\"http:\/\/footloose-project.de\"><img loading=\"lazy\" style=\"background-image: none; border-right-width: 0px; margin: 0px 5px 5px 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"Footloose_Icon\" border=\"0\" alt=\"Footloose_Icon\" align=\"right\" src=\"http:\/\/www.navision-blog.de\/images\/Using-Footloose-from-F_821B\/Footloose_Icon.png\" width=\"237\" height=\"72\" \/><\/a>Today I want to show you how to use Footloose in a very simple sample with F#.<\/p>\n<p>As a first step we create a F# project for the service contracts. Inside this project we need a service definition like this:<\/p>\n<p> <script src=\"https:\/\/gist.github.com\/4256849.js\"> <\/script>  <\/p>\n<p>This is just a definition of the remote service and the data. Now we create a F# console project for such a service and reference the service contracts project. We start by implementing the service like this:<\/p>\n<p> <script src=\"https:\/\/gist.github.com\/4256918.js\"> <\/script>  <\/p>\n<p>Now we use nuget to retrieve the latest version of Footloose. At the time of writing we need to install the pre-release of version 3.0 by <i>&quot;install-package Footloose -pre&quot;<\/i>. In the Program.fs we add the service configuration. Here Footloose wants us to specify the endpoint name, transport channel and a serializer. In order to get Footloose working we also have to retrieve a <a href=\"http:\/\/www.footloose-project.de\/request-trial-license\/\">trial license<\/a> from the website.<\/p>\n<p> <script src=\"https:\/\/gist.github.com\/4256950.js\"> <\/script>  <\/p>\n<p>Footloose wants us to provide a ServiceLocator in order to resolve the service. Normally you would use a DI container for this, but here it&#8217;s sufficient to fake a IServiceLocator like this:<\/p>\n<p> <script src=\"https:\/\/gist.github.com\/4257211.js\"> <\/script>  <\/p>\n<p>In the next step we create another F# console project for the client, reference the service contracts and install Footloose (<i>&quot;install-package Footloose -pre&quot;<\/i>). We also need to install <a href=\"https:\/\/github.com\/fsharp\/fsharpx\">FSharpx<\/a> (<i>&quot;install-package FSharpx.Core&quot;<\/i>) in order to use the &quot;Quotation to Linq Expression&quot; stuff and the new task monad. Now we are ready to build the client:<\/p>\n<p> <script src=\"https:\/\/gist.github.com\/4257136.js\"> <\/script>  <\/p>\n<p>As you can see we set up the connection and wrap our service call inside a task monad. The most interesting part is calling the service. Footloose wants to us to provide a LINQ expression:<\/p>\n<p> <script src=\"https:\/\/gist.github.com\/4257855.js\"> <\/script>  <\/p>\n<p>In order to make the client code compile we also need an active pattern which transforms the service result into something we can pattern match:<\/p>\n<p><script src=\"https:\/\/gist.github.com\/4257148.js\"> <\/script><\/p>\n<p>As the last step we configure the solution to start both projects and run the sample:<\/p>\n<p><img loading=\"lazy\" style=\"background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"startup\" border=\"0\" alt=\"startup\" src=\"http:\/\/www.navision-blog.de\/images\/Using-Footloose-from-F_821B\/startup_thumb.png\" width=\"504\" height=\"319\" \/><\/p>\n<p>The result should look like this:<\/p>\n<p><img loading=\"lazy\" style=\"background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"result\" border=\"0\" alt=\"result\" src=\"http:\/\/www.navision-blog.de\/images\/Using-Footloose-from-F_821B\/result_thumb.png\" width=\"500\" height=\"283\" \/><\/p>\n<p>The <a href=\"https:\/\/github.com\/dnauck\/FootlooseExamples\/tree\/master\/src\/FootlooseExamples.FSharpWeatherInfo\">sample code<\/a> is now part of the <a href=\"https:\/\/github.com\/dnauck\/FootlooseExamples\">FootlooseExamples project on github<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u201cFootloose is a fast and scalable asynchronous distributed computing and service library that was designed to be secure, simple to use, unobtrusive and without the need of client side code generation or proxy classes. It was developed to connect or build distributed applications on the .NET\/Mono platform with enterprise features like load-balancing, clustering, encryption, service [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[448],"tags":[664,621],"_links":{"self":[{"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/posts\/1231"}],"collection":[{"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/comments?post=1231"}],"version-history":[{"count":12,"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/posts\/1231\/revisions"}],"predecessor-version":[{"id":1249,"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/posts\/1231\/revisions\/1249"}],"wp:attachment":[{"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/media?parent=1231"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/categories?post=1231"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/tags?post=1231"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}