连接到 Microsoft Dynamics 365/2016 Web-API
Connect to Microsoft Dynamics 365/2016 Web-API
我正在尝试执行以下 API 调用
RetrieveRecordChangeHistoryRequest
我正在尝试遵循 this steps,但我无法复制代码,我遇到了一堆错误。
我已成功安装 Dynamics 365 HelperCode,但开始管理代码时我不明白为什么它不起作用。 (我有 0 个 C# 经验)
using Microsoft.Crm.Sdk.Samples.HelperCode;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
private HttpClient httpClient;
private void ConnectToCRM(String[] cmdargs)
{
Configuration config = null;
if (cmdargs.Length > 0)
config = new FileConfiguration(cmdargs[0]);
else
config = new FileConfiguration(null);
Authentication auth = new Authentication(config);
httpClient = new HttpClient(auth.ClientHandler, true);
httpClient.BaseAddress = new Uri(config.ServiceUrl + "api/data/v8.1/");
httpClient.Timeout = new TimeSpan(0, 2, 0);
httpClient.DefaultRequestHeaders.Add("OData-MaxVersion", "4.0");
httpClient.DefaultRequestHeaders.Add("OData-Version", "4.0");
httpClient.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
}
Program app = new Program();
try
{
String[] arguments = Environment.GetCommandLineArgs();
app.ConnectToCRM(arguments);
}
catch (System.Exception ex)
{ ; }
finally
{
if (app.httpClient != null)
{ app.httpClient.Dispose(); }
}
private static void DisplayException(Exception ex)
{
Console.WriteLine("The application terminated with an error.");
Console.WriteLine(ex.Message);
while (ex.InnerException != null)
{
Console.WriteLine("\t* {0}", ex.InnerException.Message);
ex = ex.InnerException;
}
}
错误
我猜你错过了重要的事情:按照说明进行操作。
在您提到的 MSDN link 中,这些是关键但基本的步骤。当您更换现成的 class 和 Main 方法时,虔诚地阅读并遵循它,这就是为什么要中断。
1.In the Solution Explorer, open Program.cs for editing.
&
1.Edit the Program.cs file.
2.Add the following property to the Program class.
This property will be initialized after a successful connection to a Dynamics 365 server.
private HttpClient httpClient;
3.In the Main method, add the following statements.
保持 class Program{}
和 static void Main()
不变。我建议您阅读有关 .net 和 c#
的优秀教程
我正在尝试执行以下 API 调用
RetrieveRecordChangeHistoryRequest
我正在尝试遵循 this steps,但我无法复制代码,我遇到了一堆错误。
我已成功安装 Dynamics 365 HelperCode,但开始管理代码时我不明白为什么它不起作用。 (我有 0 个 C# 经验)
using Microsoft.Crm.Sdk.Samples.HelperCode;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
private HttpClient httpClient;
private void ConnectToCRM(String[] cmdargs)
{
Configuration config = null;
if (cmdargs.Length > 0)
config = new FileConfiguration(cmdargs[0]);
else
config = new FileConfiguration(null);
Authentication auth = new Authentication(config);
httpClient = new HttpClient(auth.ClientHandler, true);
httpClient.BaseAddress = new Uri(config.ServiceUrl + "api/data/v8.1/");
httpClient.Timeout = new TimeSpan(0, 2, 0);
httpClient.DefaultRequestHeaders.Add("OData-MaxVersion", "4.0");
httpClient.DefaultRequestHeaders.Add("OData-Version", "4.0");
httpClient.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
}
Program app = new Program();
try
{
String[] arguments = Environment.GetCommandLineArgs();
app.ConnectToCRM(arguments);
}
catch (System.Exception ex)
{ ; }
finally
{
if (app.httpClient != null)
{ app.httpClient.Dispose(); }
}
private static void DisplayException(Exception ex)
{
Console.WriteLine("The application terminated with an error.");
Console.WriteLine(ex.Message);
while (ex.InnerException != null)
{
Console.WriteLine("\t* {0}", ex.InnerException.Message);
ex = ex.InnerException;
}
}
错误
我猜你错过了重要的事情:按照说明进行操作。
在您提到的 MSDN link 中,这些是关键但基本的步骤。当您更换现成的 class 和 Main 方法时,虔诚地阅读并遵循它,这就是为什么要中断。
1.In the Solution Explorer, open Program.cs for editing.
&
1.Edit the Program.cs file.
2.Add the following property to the Program class.
This property will be initialized after a successful connection to a Dynamics 365 server.
private HttpClient httpClient;
3.In the Main method, add the following statements.
保持 class Program{}
和 static void Main()
不变。我建议您阅读有关 .net 和 c#