cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Calling Powerapp CDS SDK methods in ASP Net Web API

Hi Community,

 

We are working on to use Microsoft Common Data Services SDK methods in ASP Net Web API. When we are creating connection to the common data service, it is giving a prompt to sign in with azure id but after login it does not return response to web API to proceed further.

               

This is working fine when we are using the SDK methods inside console application, we are able to perform CRUD operations on CDS database from console application.

 

Please suggest how to use the SDK methods in ASP.Net web API? We want to avoid the login prompt as our application is a web API service which will run in background and there will no user interaction. Is there a way to define login credentials in config file or in code to avoid the login prompt?

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Support Team
Community Support Team

Re: Calling Powerapp CDS SDK methods in ASP Net Web API

Hi @rtripathi,

 

Sorry for the delayed response. Here is the reply from pg:

 

Can you tell me a little more about how the ASP.NET site does authentication? Is this by user, (so each user is registered in AAD), or is there one user that does the authentication?

 

There is a flag that determines whether the prompt occurs:

 

var settings = new ConnectionSettings()

{

    Credentials = new UserCredentialsSettings()

    {

        UserName = "Name@microsoft.com",

        ApplicationId = "…",

        UserSource = UserSource.LoggedIn,

        //RedirectUri = "http://localhost",

    },

 

    EnvironmentId = "…",

    Tenant = "Microsoft.com",

};

 

using (var client = await settings.CreateClient())

{

 

    Task.Run(() => DoItAsync(client));

 

    Console.WriteLine("Press any key...");

    Console.ReadLine();

 

}

 

The behavior you describe for the async is correct. The await would cause the control to transfer back to the calling method, but as soon as the client is created, the control would continue after the await.

 

Regards,

Mona

 

Community Support Team _ Mona Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

7 REPLIES 7
Community Support Team
Community Support Team

Re: Calling Powerapp CDS SDK methods in ASP Net Web API

Hi @Anonymous,

 

I have escalated your question to the pg. If they have any response later, I will notice you here.

 

Regards,

Mona

Community Support Team _ Mona Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Re: Calling Powerapp CDS SDK methods in ASP Net Web API

Hi Mona,

 

Thanks for the update. Any further responses from PG? It's a critical step on which we stuck.

 

Regards

Community Support Team
Community Support Team

Re: Calling Powerapp CDS SDK methods in ASP Net Web API

Hi @Anonymous,

 

Could you please describe where you are providing the credentials? Are you using “on-behalf-of” sign-in, or are you trying to sign in a named user on the web tier?

 

Are you correctly calling await on the creation of the client instance?

 

using (var client = await ConnectionSettings.Instance.CreateClient())

{}

 

Do not use .Result in this case, on the web.

 

Regards,

Mona

Community Support Team _ Mona Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
rtripathi
Level: Powered On

Re: Calling Powerapp CDS SDK methods in ASP Net Web API

Hi Mona,

 

Thanks for your response.

 

We are trying to provide the credentials in web config file of the ASP.Net web API but whenever we are calling the CreateClient method, the login prompt appears.

 

Also We have tried calling await on the creation of the client instance, and not used Result, but in this case the control is returning to the client method without client creation. Since CreateClient is an async method, it will not wait for the response and return to the calling program, but we need client object to access the CDS entities. And if we are using Result in client creation without using await, it never returns a response.

 

 

Thanks

rtripathi
Level: Powered On

Re: Calling Powerapp CDS SDK methods in ASP Net Web API

Hi Mona,

 

I there any update on this? This is critical for our CDS implementation, and we are stuck at this point.

 

 

Thanks

Highlighted
Community Support Team
Community Support Team

Re: Calling Powerapp CDS SDK methods in ASP Net Web API

Hi @rtripathi,

 

Sorry for the delayed response. Here is the reply from pg:

 

Can you tell me a little more about how the ASP.NET site does authentication? Is this by user, (so each user is registered in AAD), or is there one user that does the authentication?

 

There is a flag that determines whether the prompt occurs:

 

var settings = new ConnectionSettings()

{

    Credentials = new UserCredentialsSettings()

    {

        UserName = "Name@microsoft.com",

        ApplicationId = "…",

        UserSource = UserSource.LoggedIn,

        //RedirectUri = "http://localhost",

    },

 

    EnvironmentId = "…",

    Tenant = "Microsoft.com",

};

 

using (var client = await settings.CreateClient())

{

 

    Task.Run(() => DoItAsync(client));

 

    Console.WriteLine("Press any key...");

    Console.ReadLine();

 

}

 

The behavior you describe for the async is correct. The await would cause the control to transfer back to the calling method, but as soon as the client is created, the control would continue after the await.

 

Regards,

Mona

 

Community Support Team _ Mona Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Zeshan
Level: Powered On

Re: Calling Powerapp CDS SDK methods in ASP Net Web API

Hello,

 

I am unable to connect with CDS SDK. I am getting an unexpected error

 

"One or more errors occurred. (Method not found: 'Void Microsoft.IdentityModel.Clients.ActiveDirectory.PlatformParameters..ctor(Microsoft.IdentityModel.Clients.ActiveDirectory.PromptBehavior)'.)"

 

on line "ConnectionSettings.Instance.CreateClient()"

 

Can you please help me out?

 

Regards,

Zeshan Khan

Helpful resources

Announcements
New Ranks and Rank Icons in April

'New Ranks and Rank Icons in April

Read the announcement for more information!

Better Together’ Contest Finalists Announced!

'Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

thirdimage

Community Summit North America

Innovate, Collaborate, Grow - The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors
Users online (3,228)