Home > Articles > Programming > Windows Programming

  • Print
  • + Share This
From the author of Writing a Client

Writing a Client

Finally, we can write a client in F# to test our endpoint. Create a new F# application. Add a reference to the FSharpWCF project and the System.ServiceModel and System.Runtime.Serialization assemblies. I also add the following config (using the WCF Service Configuration Editor, or by hand). This config creates a client binding named Client that talks to the service URL as configured within Visual Studio:

        name="Client" />

For the client to talk to the service, we instantiate a ChannelFactory, create a new channel, and then send the name to the WCF service:

open System.ServiceModel
open FSharpWCF

let factory = new ChannelFactory<ISimpleService>("Client")
let channel = factory.CreateChannel()
let name = new Name()
name.FirstName <- "Scott"
name.MiddleInitial <- 'C'
name.LastName <- "Seely"
printf "%s" (channel.MyRequestReplyMessage(name))

This prints the following line to the console:

Scott C Seely
  • + Share This
  • 🔖 Save To Your Account