Reputation: 1791
I'm trying to execute the following API Call
RetrieveRecordChangeHistoryRequest
I'm trying to follow this steps, but I can't replicate the code I get a bunch of errors.
I have installed Dynamics 365 HelperCode successfully but starting managing the code I don't get why is not working. (I have 0 experience on 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;
}
}
The errors
Upvotes: 1
Views: 3852
Reputation: 22846
I guess you missed the important thing: Follow instructions.
In the MSDN link you refer, these are crucial but basic steps. Read & Follow religiously as you replaced the readily available class & Main method it seems, thats why breaking.
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.
Keep the class Program{}
& static void Main()
untouched. I advise you to read a good tutorial on .net and c#
Upvotes: 1