Created
December 5, 2020 02:08
-
-
Save ninjarobot/e8e511e9ad2b717fdb274c8974d5f98d to your computer and use it in GitHub Desktop.
Using WCF in dotnet without a trusted certificate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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