6
I’m making a webservice where I want to return the data in JSON, how I could implement the methods, which is the best way?
- GET
- PUT
- DELETE
- POST
I did a GET method, it went like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;
using System.Web.Services;
/// <summary>
/// Summary description for WebService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService {
public WebService () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
DataClassesDataContext dc = new DataClassesDataContext();
[WebMethod]
public string getUsuario(string id)
{
var json = "";
var usuario = from result in dc.TB_USUARIOs
where result.controleusuario == Int32.Parse(id)
select result;
JavaScriptSerializer jss = new JavaScriptSerializer();
json = jss.Serialize(usuario);
return json;
}
}
None of the answers answers your question?
– durtto