在 json 中从 Dynamics CRM 365 获取数据
Getting data from Dynamics CRM 365 in json
我需要从 Dynamics CRM 365 Online 获取数据。以前有人试过这个吗?
我需要知道我需要什么样的信息(clientid、clientsecret),以便通过 c sharp 连接并将数据 (JSON) 保存到一个平面文件中。
编辑:
使用 ADAL.Net v2 如果你需要使用非异步方法。
记得把Token放在"Authorization"下的请求头中。
您需要使用 OAuth 从您的 C# 代码向 Dynamics 365 Online 进行身份验证。
// TODO Substitute your correct CRM root service address,
string resource = "https://mydomain.crm.dynamics.com";
// TODO Substitute your app registration values that can be obtained after you
// register the app in Active Directory on the Microsoft Azure portal.
string clientId = "e5cf0024-a66a-4f16-85ce-99ba97a24bb2";
string redirectUrl = "http://localhost/SdkSample";
// Authenticate the registered application with Azure Active Directory.
AuthenticationContext authContext =
new AuthenticationContext("https://login.windows.net/common", false);
AuthenticationResult result = authContext.AcquireToken(resource, clientId, new Uri(redirectUrl));
然后您可以使用 AuthenticationResult
通过 HttpClient
:
发出 HTTP 请求
using (HttpClient httpClient = new HttpClient())
{
httpClient.Timeout = new TimeSpan(0, 2, 0); // 2 minutes
httpClient.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", result.AccessToken);
//TODO Implement your WebApi calls
}
这些代码示例和其他详细信息(包括如何向 Azure AD 注册应用程序)位于 link:https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/connect-customer-engagement-web-services-using-oauth
我需要从 Dynamics CRM 365 Online 获取数据。以前有人试过这个吗?
我需要知道我需要什么样的信息(clientid、clientsecret),以便通过 c sharp 连接并将数据 (JSON) 保存到一个平面文件中。
编辑: 使用 ADAL.Net v2 如果你需要使用非异步方法。 记得把Token放在"Authorization"下的请求头中。
您需要使用 OAuth 从您的 C# 代码向 Dynamics 365 Online 进行身份验证。
// TODO Substitute your correct CRM root service address,
string resource = "https://mydomain.crm.dynamics.com";
// TODO Substitute your app registration values that can be obtained after you
// register the app in Active Directory on the Microsoft Azure portal.
string clientId = "e5cf0024-a66a-4f16-85ce-99ba97a24bb2";
string redirectUrl = "http://localhost/SdkSample";
// Authenticate the registered application with Azure Active Directory.
AuthenticationContext authContext =
new AuthenticationContext("https://login.windows.net/common", false);
AuthenticationResult result = authContext.AcquireToken(resource, clientId, new Uri(redirectUrl));
然后您可以使用 AuthenticationResult
通过 HttpClient
:
using (HttpClient httpClient = new HttpClient())
{
httpClient.Timeout = new TimeSpan(0, 2, 0); // 2 minutes
httpClient.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", result.AccessToken);
//TODO Implement your WebApi calls
}
这些代码示例和其他详细信息(包括如何向 Azure AD 注册应用程序)位于 link:https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/connect-customer-engagement-web-services-using-oauth