Archive for February, 2015

Setting Client Credentials when calling an HTTPS Web Service with the WSDL Type Provider

February 10, 2015 1 comment

.. just because it was so hard to find it online.  (This works with .Net 4.5 and F# 3.1).

You will need to add references to:

  • System.Runtime.Serialization
  • System.ServiceModel
  • System.IdentityModel
  • FSharp.Data.TypeProviders

Here’s the code, I’m sure you can work out the important bit.  It’s calling a WCF service called MyService, your names may vary:

open System
open System.ServiceModel
open System.IdentityModel
open Microsoft.FSharp.Data.TypeProviders

type MyService = WsdlService<"">

let someService = MyService.GetBasicHttpBinding_SomeService()

// important bit here!
someService.DataContext.ClientCredentials.UserName.UserName <- "MyUser"
someService.DataContext.ClientCredentials.UserName.Password <- "Password1"

// you should probably catch some exceptions here

Categories: F#, WCF