C# client library samples for SOAP clients and services
Azure DevOps Services | Azure DevOps Server 2022 - Azure DevOps Server 2019 | TFS 2018
Samples showing how to extend and integrate with Team Foundation Server and Azure DevOps Services using the legacy SOAP clients. These clients are only available in the .NET Framework version of the clients. For new development, prefer the JSON-based clients described in .NET client libraries.
Examples on this page require the following NuGet packages:
- Microsoft.TeamFoundationServer.ExtendedClient
- Microsoft.TeamFoundationServer.Client
- Microsoft.VisualStudio.Services.Client
- Microsoft.VisualStudio.Services.InteractiveClient
Example: Using SOAP-based client
// https://www.nuget.org/packages/Microsoft.TeamFoundationServer.ExtendedClient/
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
/// <summary>
/// This sample creates a new work item query under 'MyQueries', runs the query, and then sends the results to the console.
/// </summary>
public static void SampleSOAP()
{
// create TfsTeamProjectCollection instance using default credentials
using (TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri(collectionUri)))
{
// get the WorkItemStore service
WorkItemStore workItemStore = tpc.GetService<WorkItemStore>();
// get the project context for the work item store
Project workItemProject = workItemStore.Projects[teamProjectName];
// search for the 'My Queries' folder
QueryFolder myQueriesFolder = workItemProject.QueryHierarchy.FirstOrDefault(qh => qh is QueryFolder && qh.IsPersonal) as QueryFolder;
if (myQueriesFolder != null)
{
// search for the 'SOAP Sample' query
string queryName = "SOAP Sample";
QueryDefinition newBugsQuery = myQueriesFolder.FirstOrDefault(qi => qi is QueryDefinition && qi.Name.Equals(queryName)) as QueryDefinition;
if (newBugsQuery == null)
{
// if the 'SOAP Sample' query does not exist, create it.
newBugsQuery = new QueryDefinition(queryName, "SELECT [System.Id],[System.WorkItemType],[System.Title],[System.AssignedTo],[System.State],[System.Tags] FROM WorkItems WHERE [System.WorkItemType] = 'Bug' AND [System.State] = 'New'");
myQueriesFolder.Add(newBugsQuery);
workItemProject.QueryHierarchy.Save();
}
// run the 'SOAP Sample' query
WorkItemCollection workItems = workItemStore.Query(newBugsQuery.QueryText);
foreach (WorkItem workItem in workItems)
{
// write work item to console
Console.WriteLine("{0} {1}", workItem.Id, workItem.Fields["System.Title"].Value);
}
}
}
}
Authenticating
To change the method of authentication to Azure DevOps Services or Azure DevOps Server, change the VssCredential type passed to VssConnection when creating it.
Personal Access Token authentication for SOAP services
public static void PersonalAccessTokenSoapSample()
{
// Authenticate using Personal Access Token
VssBasicCredential vssBasicCredential = new VssBasicCredential(string.Empty, pat);
using (TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri(collectionUri), vssBasicCredential))
{
tpc.Authenticate();
Console.WriteLine(tpc.InstanceId);
}
}
Azure Active Directory authentication for SOAP services
public static void AADSoapSample()
{
// Authenticate using Azure Active Directory credential (requires a Azure AD-backed organization)
using (TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri(collectionUri), new VssAadCredential()))
{
tpc.Authenticate();
Console.WriteLine(tpc.InstanceId);
}
}
Visual Studio sign-in prompt (Microsoft Account or Azure Active Directory backed) for SOAP services
public static void MicrosoftAccountSample()
{
// authenticate using Visual Studio sign-in prompt
using (TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri(collectionUri), new VssClientCredentials()))
{
tpc.Authenticate();
Console.WriteLine(tpc.InstanceId);
}
}
Feedback
Submit and view feedback for