Connect to Visual Studio Team Services from WebService

csharpwinphonexaml picture csharpwinphonexaml · Mar 10, 2013 · Viewed 17.7k times · Source

How can i provide credentials to TfsTeamProjectCollectionFactory.GetTeamProjectCollection?
I am trying to develop my own WCF Service from witch I will make the request to TFS
I need this WCF service because I would like to manage my TFS files from mobile in witch I cannot use Microsoft.TeamFoundation.* dll

I have been trying this way

Uri tpcAddress= new Uri("https://myserver.visualstudio.com/DefaultCollection");
TfsConnection tfsc = new TfsConfigurationServer(tpcAddress, 
        new NetworkCredential("[email protected]", "password"));
TfsWebClient wc = new TfsWebClient(tfsc);
tfsc.Connect(ConnectOptions.IncludeServices);

Second try using Custom class derived from ICredentialsProvider

ICredentialsProvider prov = new myCredentials();
var tpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(tpcAddress, prov);
tpc.EnsureAuthenticated();
tpc.Authenticate();

public class myCredentials : ICredentialsProvider
{
    public ICredentials GetCredentials(Uri uri, ICredentials failedCredentials)
    {
        return new NetworkCredential("[email protected]", "password");
    }
    public void NotifyCredentialsAuthenticated(Uri uri)
    {
    }
}

But it works only in my machine since I am logged in to tfs.

Answer

Duat Le picture Duat Le · Mar 11, 2013

To avoid being prompted for logging in with your Live ID or having to be already signed in, you need to enable Alternate Logon Credentials and use it with your service.

This blog post tells you how:

http://blogs.msdn.com/b/buckh/archive/2013/01/07/how-to-connect-to-tf-service-without-a-prompt-for-liveid-credentials.aspx

Note that you need to have VS 2012 Update 1 installed to have this feature.

Hope this helps.