quisiera saber la forma correcta de hacer una instancia a una clase, en lo que estoy trabajando es consumir la API de Freshdesk pero no muestra nada, agregue la referencia de mi DLL, esta es la clase:
using System;
using System.Net;
using System.Text;
using System.IO;
namespace Freshdesk
{
public class CreateTicket
{
static void Main()
{
string fdDomain = "edgarrojas13"; // your freshdesk domain
string apiKey = "XG9o5QEW2HuWfbzaFM8";
string apiPath = "/api/v2/tickets"; // API path
string json = "{\"status\": 2, \"priority\": 1, \"email\":\"[email protected]\",\"subject\":\"test\",\"description\":\"confirm whether received\"}";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://" + fdDomain + ".freshdesk.com" + apiPath);
//HttpWebRequest class is used to Make a request to a Uniform Resource Identifier (URI).
request.ContentType = "application/json";
// Set the ContentType property of the WebRequest.
request.Method = "POST";
byte[] byteArray = Encoding.UTF8.GetBytes(json);
// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;
string authInfo = apiKey + ":X"; // It could be your username:password also.
authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
request.Headers["Authorization"] = "Basic " + authInfo;
//Get the stream that holds request data by calling the GetRequestStream method.
Stream dataStream = request.GetRequestStream();
// Write the data to the request stream.
dataStream.Write(byteArray, 0, byteArray.Length);
// Close the Stream object.
dataStream.Close();
try
{
Console.WriteLine("Submitting Request");
WebResponse response = request.GetResponse();
// Get the stream containing content returned by the server.
//Send the request to the server by calling GetResponse.
dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
string Response = reader.ReadToEnd();
//return status code
Console.WriteLine("Status Code: {1} {0}", ((HttpWebResponse)response).StatusCode, (int)((HttpWebResponse)response).StatusCode);
//return location header
Console.WriteLine("Location: {0}", response.Headers["Location"]);
//return the response
Console.Out.WriteLine(Response);
}
catch (WebException ex)
{
Console.WriteLine("API Error: Your request is not successful. If you are not able to debug this error properly, mail us at [email protected] with the follwing X-Request-Id");
Console.WriteLine("X-Request-Id: {0}", ex.Response.Headers["X-Request-Id"]);
Console.WriteLine("Error Status Code : {1} {0}", ((HttpWebResponse)ex.Response).StatusCode, (int)((HttpWebResponse)ex.Response).StatusCode);
using (var stream = ex.Response.GetResponseStream())
using (var reader = new StreamReader(stream))
{
Console.Write("Error Response: ");
Console.WriteLine(reader.ReadToEnd());
}
}
catch (Exception ex)
{
Console.WriteLine("ERROR");
Console.WriteLine(ex.Message);
}
}
}
}
y en un proyecto de consola hago la instancia a la clase "CreateTicket" de la siguiente manera:
using Freshdesk;
namespace FreshdeskAPI
{
class Program
{
static void Main(string[] args)
{
CreateTicket CT = new CreateTicket();
}
}
}
Al momento de querer ejecutar mi proyecto de consola, inicia y después no hace nada, no se si me falta algún código mas para que pueda consumir todo el código que esta en la clase "CreateTicket", si me pueden ayudar como puedo utilizar el código de dicha clase