jeudi 26 mars 2015

Web Service is not called by Ajax


I`m trying to call to Web Service from ajax and get string array in return,but whatever that i do ,i got 404 error in console log.


This is my client code:



$.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");}
});


and this is my Web Service code:



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();
}
}
}


Can anyone tell me what wrong with it and how to make it work?





Aucun commentaire:

Enregistrer un commentaire