Skip to content

Instantly share code, notes, and snippets.

@mikeblakeuk
Created July 20, 2018 09:22
Show Gist options
  • Save mikeblakeuk/8fa9308ac06f6a8617aca99f4ac36fe7 to your computer and use it in GitHub Desktop.
Save mikeblakeuk/8fa9308ac06f6a8617aca99f4ac36fe7 to your computer and use it in GitHub Desktop.
Adding a proxy to azure clients c# for fiddler
// Install Fiddler on a VM and open the port it listens too. Remember to enable remote connections
// http://docs.telerik.com/fiddler/Configure-Fiddler/Tasks/MonitorRemoteMachine
// Create the ServiceClient
public class ClientProvider
{
public IPowerBIClient CreatePowerBIClient()
{
var client = new PowerBIClient()
client.ApplyProxy("http://yourProxy:port");
return client;
}
}
public static class ServiceClientExtensions
{
public static void ApplyProxy<T>(this ServiceClient<T> client, string proxyUrl) where T : ServiceClient<T>
{
if (string.IsNullOrEmpty(proxyUrl))
{
return;
}
// DO NOT LEAVE THIS IN, install the certificate instead
ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, errors) => true;
// var webRequestHandler = client.GetHttpPipeline().OfType<WebRequestHandler>().LastOrDefault(); // for Hyak.Common clients
var webRequestHandler = client.HttpMessageHandlers.OfType<WebRequestHandler>().LastOrDefault();
if (webRequestHandler != null)
{
webRequestHandler.Proxy = new WebProxy(proxyUrl, true)
{
UseDefaultCredentials = true
};
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment