Access a web method using jquery

I am currently using jquery ajax to call pagemethod (which works fine);

$.ajax({
          type: "POST",
          url: "ArticleList.aspx/GetArticleTags",
          data: "{'articleId' : " + articleId + "}",
          contentType: "application/json; charset=utf-8",
          dataType: "json",
          success: function (msg) {
            if (msg.hasOwnProperty("d")) { msg = msg.d; }
            var tags = JSON.parse(msg);
            //do something
          }
        });

Pagemet,

  <WebMethod()>
  Public Shared Function GetArticleTags(ByVal articleId As Integer) As String
    Using myDb As New MyRepository
      Dim js As New JavaScriptSerializer
      Dim returnString = js.Serialize((From t In myDb.GetArticleTags(articleId) Select t.TagId, t.Tag).ToList)
      Return returnString
    End Using
  End Function

Now I am in a position where I need to access my GetArticleTags function from several pages. To quickly start and run, I could

  • Copy the function to my new aspx page and call it the same way.
  • Continue to specify the aspx source page.

Both of them are pretty trash.

Thus, the only sensible way is to call the wcf (webget) method. This will make sense: I don't have to manually serialize objects in json. It will be done for me.

- , webapp. , -, -, iis. , .., , .

wcf webapp, " WCF AJAX". , , webapp web.config .. ( 500 System.ServiceModel.ServiceActivationException)

, .... ? ( , webservice) , ?

.

+5
1

ASMX AJAX ASHX.

ASHX, ; ASMX, .

+2

All Articles