I'm currently using jquery ajax to call a pagemethod (which works great);
$.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
}
});
The pagemethod;
<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
I'm now in the position, where i need to access my GetArticleTags function from multiple pages. To quickly get it up and running i could
Both of which are pretty rubbish.
So the only reasonable way left is to call a wcf (webget) method. This will have the benefit of meaning i won't have to manually serialize the objects to json. It'll be done for me.
I do have a restful webservice in the solution already, but i'm wary about calling it from my webapp. I'd rather all the code live within my webapp, not depend on a web service which will be in a different app pool on the same iis server. It may need to be cold-started etc, and i need this to be quick.
I've added a wcf file to my webapp using the template "AJAX-enabled WCF Service". But then by doing this, i'm muddying up my webapp with endpoints in the web.config etc. (and i'm currently getting 500 System.ServiceModel.ServiceActivationException exception's)
So, down to my question.... What's the best way to call my function? (I'm thinking it has to be my restful webservice) Is there another option that i'm not considering?
Thanks muchly.
You should make an AJAX-enabled ASMX service or use an ordinary ASHX handler.
If you make an ASHX handler, you'll need to handle parsing and security yourself; I recommend an ASMX service, which can be extremely similar to your page method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With