簡體   English   中英

以 json 格式從 Dynamics CRM 365 獲取數據

[英]Getting data from Dynamics CRM 365 in json

我需要從 Dynamics CRM 365 Online 獲取數據。 有人試過這個嗎?

我需要知道我需要什么樣的信息(clientid、clientsecret),才能通過 c 進行連接並將數據(JSON)保存到一個例如平面文件中。

編輯:如果您需要使用非異步方法,請使用 ADAL.Net v2。 請記住將令牌放在“授權”下的請求標頭中。

您需要使用 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 注冊應用程序)位於此鏈接中: 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