The problem comes from the AdWordsUser constructor: it try to authenticate the user before applying the proxy settings...
I use a method which get the authtoken and use another method to instantiate the AdWordsUser to solve the problem.
public static string GetAuthToken()
{
webRequest.Method = "POST";
webRequest.ContentType = "application/x-www-form-urlencoded";
WebProxy proxy = new WebProxy("myProxy", port);
NetworkCredential credentials = new NetworkCredential();
credentials.UserName = "username";
credentials.Password = "pwd";
credentials.Domain = "mydomain";
proxy.Credentials = credentials;
webRequest.Proxy = proxy;
string postParams =
"accountType=" + HttpUtility.UrlEncode("GOOGLE") +
"&Email=" + HttpUtility.UrlEncode("") +
"&Passwd=" + HttpUtility.UrlEncode("") +
"&service=" + HttpUtility.UrlEncode("adwords") +
"&source=" + HttpUtility.UrlEncode(string.Format("{0}-{1}-{2}", "",
"", "0.0"));
byte[] postBytes = Encoding.UTF8.GetBytes(postParams);
webRequest.ContentLength = postBytes.Length;
using (Stream strmReq = webRequest.GetRequestStream())
{
strmReq.Write(postBytes, 0, postBytes.Length);
}
string retVal = "";
try
{
WebResponse response = webRequest.GetResponse();
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
string sResponse = reader.ReadToEnd();
string[] splits = sResponse.Split('\n');
foreach (string split in splits)
{
string[] subsplits = split.Split('=');
if (subsplits.Length >= 2 && subsplits[0] == "Auth")
{
retVal = subsplits[1];
}
}
}
}
catch (WebException ex)
{
throw new ApplicationException("Could not generate auth token.", ex);
}
return retVal;
}
Dictionary<String, String> dic = new Dictionary<String, String>();
dic.Add("authToken", GetAuthToken() );
AdWordsUser user = new AdWordsUser(dic);
user.Config.Proxy.Address = new Uri("http://yourProxy:port");
NetworkCredential cred = new NetworkCredential();
cred.UserName="";
cred.Password="";
cred.Domain="";
user.Config.Proxy.Credentials = cred;