What web service to use for complicate query?

2019-06-09 03:24发布

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条回答
倾城 Initia
2楼-- · 2019-06-09 03:58

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;
    }
});
查看更多
登录 后发表回答