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);
}
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.– Maniero
"But why put the code as text"? Check out the answer here
– Ronaldo Araújo Alves
@Gabrielsilva... If the service is a WS Soap with
WebMethods
, by definition all requests must be of thePOST
, now what you describe would be the patternRESTFUL
and the implementation would be different.– Leandro Angelo
Yes, I’ve been doing a research and I’m already doing a study in RESTFUL thanks for the comment :)
– Gabriel Silva
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.– Costamilam