Skip to content

Instantly share code, notes, and snippets.

@ninjarobot
Created December 5, 2020 02:08
Show Gist options
  • Save ninjarobot/e8e511e9ad2b717fdb274c8974d5f98d to your computer and use it in GitHub Desktop.
Save ninjarobot/e8e511e9ad2b717fdb274c8974d5f98d to your computer and use it in GitHub Desktop.
Using WCF in dotnet without a trusted certificate
let binding = CustomBinding ()
let textMessageEncoding = TextMessageEncodingBindingElement ()
textMessageEncoding.MessageVersion <- MessageVersion.Soap11
let transport = HttpsTransportBindingElement (RequireClientCertificate=false, AllowCookies=true, MaxReceivedMessageSize=int64(Int32.MaxValue))
binding.Elements.Add textMessageEncoding
binding.Elements.Add transport
// targetAddress should be the endpoint of the actual service you'll connect to.
let address = EndpointAddress (targetAddress)
// ServiceType will be whatever your client generated
let factory = new ChannelFactory<ServiceType>(binding, address)
// This is where you can control the certificate validation
factory.Credentials.ServiceCertificate.SslCertificateAuthentication <- X509ServiceCertificateAuthentication(CertificateValidationMode=X509CertificateValidationMode.None, RevocationMode=X509RevocationMode.NoCheck)
let service = factory.CreateChannel ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment