I’m trying to call a simple web service like this, on the client side:
$.ajax({
type: "POST",
url: "/service/local/newsservice.asmx/DoPost", // "/news/post/do",
data: {
title: _title,
markdown: _markdown,
categoryId: 1
},
success: function (data) {
alert("success!");
}
});
The actual service is:
[WebService(Namespace = "http://service.site.com/service/news")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
[ScriptService]
public class NewsService : System.Web.Services.WebService
{
[WebMethod]
[ScriptMethod]
public static void DoPost(string title, string markdown, int categoryId)
{
if (!(Roles.IsUserInRole("Owner") || Roles.IsUserInRole("Administrator")))
return;
CommunityNews.Post(title, markdown, categoryId);
}
}
When using the rewritten URL, which points to "/service/local/newsservice.asmx/DoPost", I get the following error:
The HTTP verb POST used to access path
‘/service/local/newsservice.asmx/DoPost’ is not allowed.
When I use the plain URL, I get this instead (via Firebug, the application silently fails):
DoPost Web Service method name is not valid.
What could be going on?
The built-in way of calling a web service in ASP.NET is to use a service reference, which creates JavaScript objects for you to call your web service methods.
Since you’re using jQuery instead of the proxy objects created for ASP.NET AJAX, you might have to check a couple things are configured properly: