//Step1 add ScriptService for the class & [ScriptMethod(UseHttpGet = true)]
//to the method
////// Summary description for RatingService_JSONP///
[WebService(Namespace = "http://ws.cli.det.nsw.edu.au/ns/Web2Services/RattingService",
Description = "Ratting service, this service will be plugable in any application, to support rating with comments, including reports and summaries")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
publicclassRatingService_JSONP : RatingService
{
}
[WebMethod(Description = @"Sample Please remove it")]
[ScriptMethod(UseHttpGet = true)]
publicstring[] Sample()
{
returnnewstring[] { "AAA", "BBB", "CCC", "DDD" };
}
}
//Step2
// use format=json for json format
// use callback=? for JSONP
$(document).ready(function () {
$("#btnlookup").click(function () { lookup(); });
});
function lookup() {
var addressURL = "http://localhost/Web2Services/WebServices/JSON/RatingService_JSONP.asmx/Sample?format=json&callback=?";
var outputStr = "";
$("#output").text(outputStr);
$.getJSON(addressURL, null, function (response) {
$.each(response.d, function (i, val) {
outputStr = "";
$(outputStr).appendTo("#output");
});
}); // getJson
No comments:
Post a Comment