Created
July 20, 2018 09:22
-
-
Save mikeblakeuk/8fa9308ac06f6a8617aca99f4ac36fe7 to your computer and use it in GitHub Desktop.
Adding a proxy to azure clients c# for fiddler
This file contains 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
// 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