Reputation: 21
I am working on to use Microsoft Common Data Services SDK methods in ASP.Net Web API. When I am 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 I am using the SDK methods inside console application, I am able to perform CRUD operations on CDS database from console application.
Please suggest how to use the SDK methods in ASP.Net web API? I want to avoid the login prompt as my 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
Upvotes: 1
Views: 631
Reputation: 31
I know I'm a bit late, but I figured I'd answer for anyone else running into the same issue.
If you follow the current instructions written in the Microsoft Docs, you'll end up with an App.config file that contains all the necessary values required to allow you to interact with your CDS Environment. The problem is if you include the user credentials that you would normally be prompted for and change the UserSource
value to LoggedIn
, you will still be prompted to sign in. Storing the values in the App.config file also doesn't make it ideal for an ASP.NET project.
So what you can do instead is create an instance of the ConnectionSettings
class yourself and supply all the necessary credentials.
var settings = new ConnectionSettings
{
Credentials = new UserCredentialsSettings
{
UserName = _userName,
Password = _password,
ApplicationId = _applicationId
},
EnvironmendId = _environmentId,
Tenant = _tenant
};
using (var client = settings.CreateClient().Result)
{
// Write calls to the CDS here
}
Using this approach will prevent you from getting prompted to sign in. It also allows you to store and access your credentials using ConfigurationManager.AppSettings
, making it easy to keep your credentials outside of your source code.
Upvotes: 3