Using the SmartObject OData API v4 in C#
The following C# code works with the OData v4 Employee Sample Postman collection.
C# sample code to use with the OData v4 Employee Sample Pos
public Employees ListEmployees(string OdataURL)
{
try
{
var url = $ "{OdataURL}/EmployeeSamples";
var client = new WebClient();
client.Headers.Add(HttpRequestHeader.Accept, "application/json");
client.Credentials = new NetworkCredential("User", "Password");
var content = client.DownloadString(url);
Employees employees = JsonConvert.DeserializeObject<Employees>(content);
return employees;
}
catch (WebException ex)
{
// Http Error
if (ex.Status == WebExceptionStatus.ProtocolError)
{
HttpWebResponse wrsp = (HttpWebResponse)ex.Response;
var statusCode = (int)wrsp.StatusCode;
var msg = wrsp.StatusDescription;
throw ex;
}
else
{
throw ex;
}
}
}
}
// Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(myJsonResponse);
public class Value
{
public int ID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public DateTime HireDate { get; set; }
public int DepartmentCode { get; set; }
public string Joblevel { get; set; }
}
public class Employees
{
public string Context { get; set; }
public int Count { get; set; }
public List<Value> value { get; set; }
}