简体   繁体   English

以 json 格式从 Dynamics CRM 365 获取数据

[英]Getting data from Dynamics CRM 365 in json

I need to get data from Dynamics CRM 365 Online.我需要从 Dynamics CRM 365 Online 获取数据。 Anyone tried this before ?有人试过这个吗?

I need to know what kind of information (clientid, clientsecret) I need, to connect through c sharp and save data (JSON) into a for example a flatfile.我需要知道我需要什么样的信息(clientid、clientsecret),才能通过 c 进行连接并将数据(JSON)保存到一个例如平面文件中。

edit: use ADAL.Net v2 If you need to use the non async method.编辑:如果您需要使用非异步方法,请使用 ADAL.Net v2。 Remember to put the Token in the request header under "Authorization".请记住将令牌放在“授权”下的请求标头中。

You need to use OAuth to authenticate to Dynamics 365 Online from your C# code.您需要使用 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));  

You can then use the AuthenticationResult to make HTTP requests with HttpClient :然后,您可以使用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
}

These code samples and additional details, including how to register an application with Azure AD, are in this link: https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/connect-customer-engagement-web-services-using-oauth这些代码示例和其他详细信息(包括如何向 Azure AD 注册应用程序)位于此链接中: https : //docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/connect-customer-engagement-网络服务使用 oauth

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM