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 an .asmx, it never returns with the data. I know this has been mentioned before in many forums, but I did not have issues in V1.0 of the SDK. When I try to use V5+ I can't seem to get the information back. Any ideas on overcoming the issue?
Any help would be great.
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; } }