4 messages in com.googlegroups.adwords-apiAdWords API switching between live an...
FromSent OnAttachments
David29 Jul 2008 07:54 
AdWords API Advisor29 Jul 2008 11:51 
David29 Jul 2008 12:12 
AdWords API Advisor01 Aug 2008 09:28 
Subject:AdWords API switching between live and sandbox - something I don't understand
From:David (cont@akamarketing.com)
Date:07/29/2008 07:54:23 AM
List:com.googlegroups.adwords-api

Hi read a previous message on this group about switching between the two different evironments G offter to adwords api developers. I want code whereby I can either set a param on a getService(string servicetype, bool sandbox) type of method or overall via the web.config. I have different config sections in web.config for live and sandbox and the changing off the values for sandbox v live is going fine. In fact so too is the changing of the .URL property on my new created services, but I just don't understand why...

Here's some code I written

//are we using the sandbox or live API environment? if(sandbox){environment = "adwordsSandbox";} else{environment = "adwordsLive";}

Hashtable headers = (Hashtable)ConfigurationManager.GetSection(environment); if (headers != null && headers.Count == 5) //the section a) must be there { //and b) must have exactly 5 values email = headers["email"].ToString(); password = headers["password"].ToString(); useragent = headers["useragent"].ToString(); applicationToken = headers["applicationToken"].ToString(); developerToken = headers["developerToken"].ToString(); } else { //throw an error if the section is missing or malformed throw new Exception("The \"" + environment + "\" configuration section in the web.config file is missing or incorrectly formed. It must have five elements: email, password, useragent, applicationToken and developerToken to be considered well formed."); }

//create the appropriate service based on the serviceTypes enum passed in if(serviceTypes == ServiceTypes.Account) { AccountService service = new AccountService(); //HERE I'm creating a sandbox object??? if(sandbox) {service.Url = "https://sandbox.google.com/api/adwords/v12/ AccountService";} else{ service.Url = "https://adwords.google.com/api/ adwords/v12/AccountService";}

What I don't understand is how this works, I mean why did I first have to create an instance of anything? I added a web reference to to the SANDBOX campaign wsdl file via visual studio, I placed a using com.google.sandbox statement at the top of my file so when I call AccountService service = new AccountService() in the above code Im creating a sandbox object? but yet by changing its URL it effectively become a LIVE object.

Do I need to add web references for all the services I need to use or can I simple create a false AccountService() even if I want campaignservice() and just change the URL.

Anyone shed any light on this.