HTTP protocols

Asked

Viewed 40 times

0

I’m new to development and I’m learning how to make a web service

below this my method of consultation, insertion and removal. they are already working, however I wanted to know how to pass in the code which method to use.

Att

ex: method consult when "GET" method insert using "POST" Delete method using "DELETE" method update using "PUT"

[WebMethod]
public string ConsultarSensor()
{
   NegSensores regrasSen = new NegSensores();
   List<SEN> colecao = new List<SEN>();
   JavaScriptSerializer jss = new JavaScriptSerializer();

   string jsonSen = string.Empty;

   colecao.AddRange(regrasSen.ConsultarSen(null));
   jsonSen = jss.Serialize(colecao);

   return jsonSen;
}

[WebMethod]
public void InsertSen()
{
   NegSensores regrasSen = new NegSensores();
   regrasSen.InsertSensor("SEN", "Input_20", false, 30, 15, "aaaaaaaaaa", "ouhjflkdfh",1);
}

[WebMethod]
public void DeleteSensor()
{
   NegSensores regrasSen = new NegSensores();
   regrasSen.DeletSen(6);   
}
  • 2

    Put the code as text and take this try-ctach that they’re not doing anything useful, they’re actually doing bad things in the code. A tip for beginners: Never use something you don’t understand, first understand, with depth, then you can use it. Another suggestion I would give and I know will not be followed. Start doing simple things, after you master these go to the most complex.

  • "But why put the code as text"? Check out the answer here

  • 1

    @Gabrielsilva... If the service is a WS Soap with WebMethods, by definition all requests must be of the POST, now what you describe would be the pattern RESTFUL and the implementation would be different.

  • Yes, I’ve been doing a research and I’m already doing a study in RESTFUL thanks for the comment :)

  • You are using C# but do not say if you are using ASP.NET Core, if yes just put the notes [HttpGet], [HttpPost], [HttpPut], etc.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.