Rest client response always null

1,136 views
Skip to first unread message

Conrad Chamerski

unread,
Nov 6, 2012, 3:09:19 PM11/6/12
to rest...@googlegroups.com

I create a GUI application to retrieve issue's data from redmine using RestSharp. I followed exactly what is supposed to be done from their documentation, but I keep on receiving a null response. Why is it always null, is there a connection issue?

The var response = client.Execute<T>(request) is always null when request.RootElement = "issue" is commented out. When I do use it, I get an exception of "Object was not instantiated".


Manager.cs

public class Manager
{
    private string _baseUrl;
    private string _user;
    private string _password;

    public Manager(string user, string password, string baseUrl)
    {
        _user = user;
        _password = password;
        _baseUrl = baseUrl;
    }

    private T Execute<T>(RestRequest request) where T : new()
    {
        var client = new RestClient();

        client.BaseUrl = _baseUrl;

        client.Authenticator = new HttpBasicAuthenticator(_user, _password);

        //TODO: replace string 4110 with a passed ticket # as parameter
        //request.AddParameter("issueId", "4110", ParameterType.UrlSegment); // used on every request
        var response = client.Execute<T>(request);

        if (response.ErrorException != null)
        {
            throw response.ErrorException;
        }

        return response.Data;
    }

    public Issue GetIssue(int issueId)
    {
        var request = new RestRequest();
        request.Resource = "issues/{id}";
        //request.RootElement = "issue";

        request.AddParameter("id", issueId, ParameterType.UrlSegment);

        return Execute<Issue>(request);
    }

Form1.cs

private void button1_Click(object sender, EventArgs e)
{
    Manager manager = new Manager("user", "password", "http://website/redmine");

    Issue issue = manager.GetIssue(4110);
}

Issue

public class Issue
{
    //public List<Custom_field> Custom_fields { get; set; }

    public int Id { get; set; }

    public Element Project { get; set; }

    public Element Author { get; set; }

    public Element Tracker { get; set; }

    public Element Status { get; set; }

    public Element Priority { get; set; }

    public Element Assigned_to { get; set; }

    public Element Category { get; set; }

    public string Subject { get; set; }

    public string Description { get; set; }

    public string Start_date { get; set; }

    public int Done_ratio { get; set; }

    public double Estimated_hours { get; set; }

    public DateTime Due_date { get; set; }

    public string Created_on { get; set; }

    public string Updated_on { get; set; }

}

pamlo dev

unread,
Nov 13, 2012, 3:14:58 PM11/13/12
to rest...@googlegroups.com
Hello man , con u help me please with How i con make  RESTFul MVC4  C# and HTTP API Client for .NET , iam working in project and i am new with c#  and i have one server i need to make my project read and and wirght to this server and loco host but i do not know and thank you so much
Reply all
Reply to author
Forward
0 new messages