Routing web requests to a WCF service through Quota Guard from Azure Function App

June 2019 Update : QuotaGuard is now available natively on Azure at the following link : QuotaGuard Listing on Azure.

You can also use the below directions with our direct service at : https://www.quotaguard.com

We have had a few customers ask for help with a WCF/Azure configuration, so we will share some working code below that customers have found helpful :

binding.Security.Mode = BasicHttpSecurityMode.Transport;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;

//Wrap binding custom binding to route request through proxy with credential authentication
var customBinding = new CustomBinding(binding);
var httpElement = customBinding.Elements.Find<HttpTransportBindingElement>();
httpElement.ProxyAddress = new Uri(Environment.GetEnvironmentVariable(ProxyURL));
httpElement.ProxyAuthenticationScheme = AuthenticationSchemes.Basic;
httpElement.UseDefaultWebProxy = false;

using (var webClient = new TransparencyPlatformClient(customBinding, FinalEndpoint)
{
  webClient.ClientCredentials.ClientCertificate.Certificate = Certificate;
  webClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode =
    X509CertificateValidationMode.PeerOrChainTrust;
  var xmlString = XmlString(xml);

  webClient.ClientCredentials.UserName.UserName = ProxyUserName;
  webClient.ClientCredentials.UserName.Password = ProxyPassword;

  webClient.sendMessage(YourMessage);;
}

Why is a CustomBinding used?

The pitfall is that the proxy settings on BasicHttpBinding don’t seem to be properly implemented as there is no way to get it to use the proper credentials.