tags:

views:

671

answers:

2

Hi

I am trying to send TFS credentials to the server for connecting TFS server using below code

TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer().This method is expecting two input parameters.one is of type string(tfs url as string) and another one is of type ICredentialsProvider.I am unable to create instance of this class and unable to send TFS credentials to Getserver method.Please help me if any body has idea about it.

Thanks Suneetha.

+1  A: 

What sort of errors are you getting when you create an ICredentialsProvider?

You should be able to instantiate a UICredentialsProvider object that implements ICredentialsProvider.

Alternatively you can construct a TeamFoundationServer instance and pass credentials through the constructor.

These links might help:

dariom
Hi I am using this method to get version control serevr. NetworkCredential creds = new NetworkCredential(AppSettings.Username, AppSettings.Password, AppSettings.Domain); ICredentials ICP = (ICredentials)creds; TeamFoundationServer tfs = new TeamFoundationServer(AppSettings.TfsUrl, ICP); tfs.EnsureAuthenticated(); return tfs.GetService(typeof(VersionControlServer)) as VersionControlServer;I am able to connect now but it is returning versioncontrolserver as null.Thankssuneetha
Hi Suneetha. I can't see any problem in the code. Perhaps the URL is incorrect? Are you including the port number for TFS (8080 by default for HTTP connections)? Example: "http://tfs.dev.company.com:8080". You could change the last line to "return (VersionControlServer) tfs.GetService(typeof(VersionControlServer))" which will throw an exception if the cast fails. This might help uncover any casting errors. Otherwise perhaps the user does not have access to the version control system in TFS?
dariom
A small point: The line "ICredentials ICP = (ICredentials)creds;" is unnecessary: you can just pass the variable "creds" to the TeamFoundationServer constructor instead of "ICP" since NetworkCredential implements ICredentials.
dariom
A: 

NetworkCredential networkCredential;

        if (Username != null && Password != null)
        {
             if (Domain != null)
                  networkCredential = new NetworkCredential(Username, Password, Domain);
             else
                  networkCredential = new NetworkCredential(Username, Password);
         }
         else
         {
              networkCredential = CredentialCache.DefaultNetworkCredentials;
         }


        TeamFoundationServer TFS = new TeamFoundationServer( stringTFSURL, networkCredentials);
Alex