【发布时间】:2019-09-18 09:37:51
【问题描述】:
我有一个使用 Windows 身份验证的现有 .net 解决方案。现在我在现有解决方案中添加了另一个 Web 服务项目,并在那里创建了一个 .asmx 服务。通过 ajax,我尝试如下调用该 Web 服务
Ajax 请求
$.ajax({
type: "POST",
url: "HelloService/HelloData.asmx/HelloWorld",
data: "{parameterList:" + JSON.stringify(model) + "}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
cache: false,
success: function (jsondata) {
alert(jsondata);
}, error: function (x, e) {
alert("Error")
}
});
这是我的 .asmx 服务
namespace HelloService
{
/// <summary>
/// Summary description for HelloData
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class HelloData : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld(string parameterList)
{
return "Hello World";
}
}
}
在上面的代码中,我在“Application_error”方法的“Global.asax.cs”文件中收到No web service found at: /HelloService/HelloData.asmx. 错误。这里出了什么问题,需要做什么?
【问题讨论】:
-
请问为什么要在 2019 年创建新的 ASMX 服务?你为什么不改用Web API?
-
你的 JavaScript "data: "{parameterList:" + JSON.stringify(model) + "}" 错了应该是 data: '{parameterList: "' + JSON.stringify(model) + '"}' this. and remove async: true, 即使没有响应,它也会执行下一条语句。
标签: jquery asp.net .net web-services webmethod