Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I am trying to return just a simple string after executed a store procedure using restful in c# .
This is my code (i know it is not a good code)
<pre> 
public string Get(string numero)
{
    string conexionString = "";
    SqlConnection conexion = null;
    var answer = "";
    try
    {
       conexion = new SqlConnection();
       conexion.ConnectionString = conexionString;
       conexion.Open();
       SqlCommand cmd = new SqlCommand("validar_cliente_factura", conexion);
       cmd.CommandType = CommandType.StoredProcedure;
       cmd.Parameters.Clear();
       cmd.Parameters.AddWithValue("@CTE_NUMERO", numero);
       SqlParameter returnValue = new SqlParameter("@RESPUESTA", 
 SqlDbType.NVarChar);
       returnValue.Direction = ParameterDirection.Output;
       cmd.Parameters.Add(returnValue);
       cmd.ExecuteNonQuery();
       answer = (string)returnValue.Value;
    }
    catch (Exception)
   { }
   finally
   {
      conexion.Close();                
   }
   return answer;
  }


When i run: https://localhost:44322/API/Test/A-5367
<message>No HTTP resource was found that matches the request URI 'https://localhost:44322/API/Test/A-5367'.
<messagedetail>No action was found on the controller 'Test' that matches the request.

What I have tried:

I had try some examples including the one when you created the example which is use
// GET api/values/5
      public string Get(int id)
      {
          return "value";
      }
Posted
Updated 12-Aug-22 9:33am

1 solution

Have you added [HttpGet] before this method? Also, try to return an ActionResult rather than just a string.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900