What web service to use for complicate query?

北城以北 提交于 2019-12-23 04:54:32

问题


A naive question about web service.

I need to implement a complicate query. The client need to pass in many parameters to the server, and the server will send back response will many data fields.

What type of web service is suitable for this? I know that RESTful POST method is meant to "create" an object, but can I use POST for implementing this?

Or SOAP is better for this?


回答1:


Here it is.

//for the Controller

    public JsonResult GetData(string param1, string param2)            
    {
        List<YourModecClass> data = new List<YourlModelClass>();

            //Mockup data only...you should get the data from DB source
            data = new List<YourModelClass>();
            data.Add(new YourModelClass() { Region = "", Value_TY = 0});
            data.Add(new YourModelClass() { Region = "", Value_TY = 0 });
        return Json(data, JsonRequestBehavior.AllowGet);
     }

//jQuery

function getServerData() {
var entity = { 
    param1: param1 //--> ths is a variable
    param2: "value" //--> hardcoded
}
var parameter = JSON.stringify(entity); 

$.ajax({
    type: "POST",
    url: url + "/GetData",  
    data: parameter,
    dataType: "json",
    contentType: "application/json",
    async: true,
    beforeSend: function () {
    },
    success: function (response, status, xhr) {
        yourJavascriptVariable = response;
        doSomethingWithreceivedDataAbove();
    },
    error: function (xhr, status, error) {
        debugger;
    }
});


来源:https://stackoverflow.com/questions/27608850/what-web-service-to-use-for-complicate-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!