Monday, November 7, 2011

i++ kind of functionality in F#

As F# is immutable language, we will not be able to use i++ kind of functionality directly. You will have to combine the "mutable" and "module" feature of F# to achieve the i++ kind of functionality. Below here is the simple demonstration of this;

module Foo
       let mutable m_field = 0
       let next () =
             m_field <- m_field + 1; m_field

Just use Foo.next () whereever you need i++ kind of functionality.

Wednesday, October 19, 2011

Consume WCF REST service in F#

Today I successfully implemented the code for consuming WCF REST service in F#. Funny part here is that, this is my first program in F#.. LOL

Ok.. Here is the code for consuming WCF REST in F#.

module FSModule

#light

open System
open System.Text
open System.Net
open System.IO
open System.Web

// F# uses indenting to define scope. So ensure that you indent properly to get it working
let GetDataFromRest =
     let buffer = Encoding.ASCII.GetBytes("<HelloService_SayHello><input>Hello from F#</input></HelloService_SayHello>") //This is needed if its a POST call
     let req = WebRequest.Create(new Uri("http://localhost/HelloService.svc/SayHello")) :?> HttpWebRequest
     req.Method <- "POST"
     req.ContentType <- "application/xml" //Use accordingly XML or JSON
     req.ContentLength <- int64 buffer.Length
     let reqSt = req.GetRequestStream()
     reqSt.Write(buffer,0,buffer.Length)
     reqSt.Flush()
     req.Close()

     let res = req.GetResponse () :?> HttpWebResponse
     let resSt = res.GetResponseStream()
     let sr = new StreamReader(resSt)
     let x = sr.ReadToEnd()
     sr.Close()
     x.ToString()

Done... To invoke this, you can either use F# or C# or even VB.NET :)

F#

let result = GetDataFromRest()
printfn result

C#

string result = FSModule.GetDataFromRest()

Friday, October 14, 2011

Smartphone App for Mainframe systems - A thought

Recently I submitted this idea for one of the competition. The competition was for design approaches for smartphone app for mainframe systems.
Mainframe application provides functionality for uploading the JCL jobs via FTP and executing them. And iPhone SDK supports FTP functionality. Hence we can leverage these functionalities for running the Mainframe jobs from the iPhone or iPad Apps (even we can extend further to Android as well).



Here is the simple demonstration how this can be achieved



1) User keys in the instructions to be run in the mainframe application

2) Clicks Submit button

3) Using the iPhone SDK create the Commands.jcl file

4) Open the FTP connection to the IBM mainframe (FTP details will be pre-configured using the Settings screen)

5) Run the following commands

        a. quote site filetype=jes

        b. quote site jeslrecl=80

        c. put commands.jcl

This will kicks of the job and execute the instructions in the commands.jcl file.

6) Once the instructions are executed, the response will be available in the spooled output file “JOB#####.n” where ‘n’ is the dataset number. (The challenge here will be when to read this response file)

I am yet to hear the result from the competition. Hope this idea wins me an iPad2.. LOL

Tuesday, September 6, 2011

Silverlight and SEO

Recently I came across a very good article on Silverlight and SEO techniques for public facing Silverlight based websites. Check the link below for more;

Silverlight and SEO

Thursday, September 1, 2011

WCF RIA and custom methods

There may be times where-in you will have to add some custom coded methods along with the auto generated EF wrapper methods. You may be wondering how to do. Don't worry.. RIA provides support for that and is very simple. Follow these steps to get this work;

Server-side

In the Domain service class, decorate the custom methods with the [Invoke] attribute. Job done!!

[Invoke]
public string SayHello ()
{
        return "Hello";
}

Client-side

This is how you can access the RIA custom methods;

HelloDomainServiceContext ds = new HelloDomainServiceContext();
ds.SayHello( (p) => {var result = p.Value;}, null);