用于复杂查询的Web服务是什么?

时间:2014-12-22 19:02:11

标签: web-services rest post soap

关于网络服务的一个天真的问题。

我需要实现一个复杂的查询。客户端需要将许多参数传递给服务器,而服务器将发送回响应将许多数据字段。

哪种类型的网络服务适合这种情况?我知道RESTful POST方法是为了“创建”一个对象,但是我可以使用POST来实现它吗?

或者SOAP更适合这个?

1 个答案:

答案 0 :(得分:1)

在这里。

//用于控制器

    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;
    }
});
相关问题