public void GetBuildDefinitions(TeamCityProject project, string userName, string password, GetBuildDefinitionsCompleteDelegate complete) { WebClient webClient = new WebClient { Credentials = new NetworkCredential(userName, password) }; var projectDetailsUrl = new Uri(project.RootUrl + project.Href); webClient.DownloadStringCompleted += (s, e) => { XDocument doc = XDocument.Parse(e.Result); if (doc.Root == null) { throw new Exception("Could not get project build definitions"); } XElement buildTypes = doc.Root.Element("buildTypes"); if (buildTypes == null) { throw new Exception("Could not get project build definitions"); } TeamCityBuildDefinition[] projects = buildTypes .Elements("buildType") .Select(buildTypeXml => new TeamCityBuildDefinition(project.RootUrl, buildTypeXml)) .ToArray(); complete(projects); }; webClient.DownloadStringAsync(projectDetailsUrl); }