Forum Discussion
MustangProgrammer
Jan 30, 2025Copper Contributor
Graph API getAsync() in C#
If I use graph in a console application I get the information that I request. Such as test = await graphClient.Users.GetAsync(); If I try this in a WebMethod in the code behind of a page or in a...
Kidd_Ip
Feb 03, 2025MVP
Try below to set up an asynchronous web method:
[WebMethod]
public async Task<string> GetUserData()
{
try
{
var graphClient = new GraphServiceClient();
var user = await graphClient.Users.GetAsync();
return user.DisplayName;
}
catch (Exception ex)
{
return ex.Message;
}
}