views:

39

answers:

1

I am using jQuery to consume a web service I built, the input is currently serialized JSON, as well as the output via jQuery AJAX.

I'd like to make the service more RESTful by adding URI query string parameters so that users can access the same same page of search results, query string, etc. etc., when they save the URI as their state.

I don't believe my web service needs much changing. Should I access and re-write the URI using jQuery? If so does anyone have any posts that demonstrate how to do this?

Thanks

Web service:

/// <summary>
/// Summary description for WebService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 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
{
    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public OutputData updateProductsList(InputData request)
    {
        //...//

        return result;
    }

And the Ajax request using JSON Serialization:

//Build the ajax Request
    var req = { request: { qtype: "ProductName", query: queryText, page: resultPage, rp: rP} };

    $.ajax({
        type: "POST",
        url: "/webservice/WebService.asmx/updateProductsList",
        data: JSON.stringify(req),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
A: 

I don't know about the web service, but on the jQuery side, if qtype, query, page and rP should be your parameters, just change:

data: JSON.stringify(req)

to

data: req.request

or just

var request: { qtype: "ProductName", query: queryText, page: resultPage, rp: rP} };
//and
data: request

Of course you have to change your web service to accept those GET parameters.

I hope I got your question right.

Felix Kling
Hmmm, I think I follow, I need to change the way I'm getting the input data from the page to accept the URI data? Also am I still sending data using JSON? Or is it a form post?
jordan.baucke
Felix Kling
thanks Felix I ended up using: jQuery BBQ http://benalman.com/code/projects/jquery-bbq to grab the parameters and re-write the URI.If I want to provide more direct access to my web service I will update it.
jordan.baucke