Reputation: 1916
I'm trying to connect to TeamFoundationServer
hosted at visualstudio.com using its client API with a Console Application, but I get this error:
TF400813: Resource not available for anonymous access. Client
My code:
private static void Main(string[] args)
{
Uri collectionUri = new Uri("https://MyName.visualstudio.com/DefaultCollection");
TfsTeamProjectCollection collection =
new TfsTeamProjectCollection(
collectionUri,
new System.Net.NetworkCredential(@"[email protected]", "MyPassword"));
WorkItemStore workItemStore = collection.GetService<WorkItemStore>();
}
Upvotes: 11
Views: 27105
Reputation: 78623
Set up alternate credentials for your account. You can use alternate credentials for the command-line clients and as a NetworkCredential
parameter.
Upvotes: 4
Reputation: 2028
You have to call the EnsureAuthenticated()
method from TfsTeamProjectCollection
:
private static void Main(string[] args)
{
Uri collectionUri = new Uri("https://MyName.visualstudio.com/DefaultCollection");
NetworkCredential credential = new NetworkCredential("USERNAME", "PASSWORD");
TfsTeamProjectCollection teamProjectCollection = new TfsTeamProjectCollection(collectionUri, credential);
teamProjectCollection.EnsureAuthenticated();
WorkItemStore workItemStore = teamProjectCollection.GetService<WorkItemStore>();
WorkItemCollection workItemCollection = workItemStore.Query("QUERY HERE");
foreach (var item in workItemCollection)
{
//Do something here.
}
}
I hope it has solved your problem.
Upvotes: 13