[英]How to call ASMX webservice from MVC view?
Following are the WebService method i am trying to consume-: 以下是我尝试使用的WebService方法:
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
using ajax call for calling this method 使用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);
}
});
But everytime i am getting error of resource not found might be because i am calling it from MVC view, i also tried to put whole localhost path http://localhost:60005/ still got the error of resource not found, could someone give me a small example of calling asmx webservice from MVC view? 但是每当我收到找不到资源的错误时,可能是因为我是从MVC视图调用它的,所以我也试图将整个本地主机路径http:// localhost:60005 /仍然得到找不到资源的错误,有人可以给我一个从MVC视图调用asmx Web服务的小例子?
Try with adding this line to your RouteConfig: 尝试将此行添加到RouteConfig中:
routes.IgnoreRoute("{*x}", new { x = @".*\.asmx(/.*)?" });
also, uncomment this line in your asmx web service class: 另外,在您的asmx Web服务类中取消注释此行:
[System.Web.Script.Services.ScriptService]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.