0

This exception is thrown when I need to call the Registry of my project and get all services displayed in client.It worked yesterday but dont know why its not working now.Can anyone help with me with this?

This is my method to get all services to client from the registry api

private void btnGetAll_Click(object sender, RoutedEventArgs e)
    {
        Services services;
        User user = User.Instance;

        //Api Call is made.
        string url = "http://localhost:14470/api/AllServies/ " + Rtoken;

        var clinet = new RestClient(url);
        var request = new RestRequest();
        var response = clinet.Post(request);
        List<Services> data = new List<Services>();
        data = JsonConvert.DeserializeObject<List<Services>>(response.Content.ToString());
        List<Services> gridData = new List<Services>();
        foreach (Services line in data)
        {

            //services = JsonConvert.DeserializeObject<List<Services>>(line);
            /*if (services.Status.Equals("Denied"))
            {
                logout();
                break;
            }*/
            gridData.Add(line);
        }
        // Services test = serviceInfo.SelectedItem as Services;
        serviceInfo.ItemsSource = gridData;
    }

This is the all service controller of my registry api

// POST: api/AllServices
    [Route("api/AllServies/{token}")]
    [HttpPost]
    public IHttpActionResult Post([FromBody] int token)
    {
        //AuthInterface foob = auth.initServerConnection();
        // Ilist return for returning list with multple types
        //token validation
        string validate = foob.Validate(token);
        if (validate.Equals("Not Validated"))
        {
            //if valid token

            // path to the text file
            string path = "C:\\Users\\ravin\\Desktop\\assignment_1_DC\\Services.txt";
            List<string> services = File.ReadAllLines(path).ToList();

            List<Rdetails> regservice = new List<Rdetails>();

            //checking for every line
            foreach (var service in services)
            {
                //deserlizing text and assigning values to RegistryDetail type object
                Rdetails rDetail = JsonConvert.DeserializeObject<Rdetails>(service);

                // add details to the created Registry details type list
                regservice.Add(rDetail);

            }

            return Ok(regservice);

        }
        else
        {
            // if token is unvalid

            Rresponse reg = new Rresponse();
            
            reg.RegStatus = "Denied";
            reg.RegReason = "Authentication Error";
            List<Rresponse> output = new List<Rresponse>();
            output.Add(reg);

            return Ok(output);
        }
    }
}

}

sd gopal
  • 1
  • 2
  • You probably have a cookie issue. Try deleting the cookie and see if code works. The Token is a logon cookie. The cookie that is being sent is being rejected and you need to login again. The same cookie is used in both a Browser and in c#. Often code works because you used a browser to connect and then the c# app used the cookie stored by the browser. You can try to connect with browser and then run c#. If you get a connection than you need to fix c# to request a login token in the code. – jdweng Sep 25 '22 at 05:40
  • No pictures of code please. Copy the code and paste it into your question (which you can _Edit_). You can format the text of your code as `code` using the `{}` button. Generally, an _Internal Server Error_ (status code 500) means the called server threw an exception – Flydog57 Sep 25 '22 at 05:40

0 Answers0