[英]How to call ASMX webservice from MVC view?
以下是我尝试使用的WebService方法:
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
使用ajax调用来调用此方法
$.ajax({
type: "POST",
url: "/WebServices/WebService1.asmx/HelloWorld",
data: "{}",
contentType: "application/json; charset=utf-8",
success: function (msg) {
var data = msg.d;
},
error: function (msg) {
alert(msg.responseText);
}
});
但是每当我收到找不到资源的错误时,可能是因为我是从MVC视图调用它的,所以我也试图将整个本地主机路径http:// localhost:60005 /仍然得到找不到资源的错误,有人可以给我一个从MVC视图调用asmx Web服务的小例子?
尝试将此行添加到RouteConfig中:
routes.IgnoreRoute("{*x}", new { x = @".*\.asmx(/.*)?" });
另外,在您的asmx Web服务类中取消注释此行:
[System.Web.Script.Services.ScriptService]
您在这里有一个不错的教程:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.