Javascript Ajax不调用Web服务

Javascript Ajax不调用Web服务,javascript,c#,ajax,web-services,Javascript,C#,Ajax,Web Services,我试图从ajax调用Web服务并得到字符串数组作为回报,但不管我做什么,控制台日志中都出现了404错误 这是我的客户代码: $.ajax({ url: "http://localhost:55397/WebService1.asmx/GetList", cache: false, type: "POST", contentType: "application/json; charset=utf-8", dataType: 'json',

我试图从ajax调用Web服务并得到字符串数组作为回报,但不管我做什么,控制台日志中都出现了404错误

这是我的客户代码:

 $.ajax({
        url: "http://localhost:55397/WebService1.asmx/GetList",
        cache: false, type: "POST", contentType: "application/json; charset=utf-8",

        dataType: 'json',
        success: function (data) {
            tags = data.d;
        },
        error: function () { alert("AutoComplete Server not found");}
    });
这是我的Web服务代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using ExpressDeal.Models;
using ExpressDeal.Controllers;
using System.Web.Script.Services;


namespace ExpressDeal
{
    /// <summary>
    /// Summary description for WebService1
    /// </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. 

    public class WebService1 : System.Web.Services.WebService
    {
        private BaseLogic bl = new BaseLogic();

        [WebMethod]
        [ System.Web.Script.Services.ScriptMethodAttribute()]
        //[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Xml)]
        public string [] GetList()
        {
            return bl.Context.Items.Select(i=>i.Name).ToArray();
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Web;
使用System.Web.Services;
使用ExpressDeal.Models;
使用ExpressDeal.Controllers;
使用System.Web.Script.Services;
命名空间ExpressDeal
{
/// 
///WebService 1的摘要说明
/// 
[WebService(命名空间=”http://tempuri.org/")]
[WebServiceBinding(ConformsTo=WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
//要允许使用ASP.NET AJAX从脚本调用此Web服务,请取消注释以下行。
公共类WebService 1:System.Web.Services.WebService
{
私有BaseLogic bl=新BaseLogic();
[网络方法]
[System.Web.Script.Services.ScriptMethodAttribute()]
//[ScriptMethod(UseHttpGet=true,ResponseFormat=ResponseFormat.Xml)]
公共字符串[]GetList()
{
返回bl.Context.Items.Select(i=>i.Name.ToArray();
}
}
}

有人能告诉我它有什么问题以及如何使它工作吗?

尝试将您的方法设置为静态:

        [WebMethod]
        [ System.Web.Script.Services.ScriptMethodAttribute()]
        //[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Xml)]
        public static string [] GetList()
        {
            return bl.Context.Items.Select(i=>i.Name).ToArray();
        }

从简单开始。粘贴URL
http://localhost:55397/WebService1.asmx/GetList
进入浏览器栏?好的,asmx不会;不支持JSON序列化。永远都是肥皂。似乎您想使用WebAPI而不是asmx。错误:“/”应用程序中的服务器错误。当然,您不能这样调用web服务。Webservice正在使用SOAP(默认情况下),您尝试通过POST方法调用它?您可以检查以下链接: