0
我正在處理ASP.NET Web應用程序。webservice不被調用
我想使用jquery ajax來調用Web服務。 webservice將返回一個字符串。
這是我的web服務:
[WebService(Namespace = "http://localhost/")]
[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 MyWebService : System.Web.Services.WebService
{
[WebMethod]
public string GetStringForPerson(string Personname, int StartYear, int EndYear)
{
string S = "Hello" + Personname + " You where born between " + StartYear + " and " + EndYear;
return S;
}
}
而Ajax的功能將其稱之爲:
function GetStringForPerson(Name) {
$.ajax({
type: "POST",
url: "Service/MyWebService.asmx/GetStringForPerson",
dataType: "json",
data: "{'Personname':Name, 'StartYear':'2001', 'EndYear':'2005'}",
contentType: "application/json; charset=utf-8",
success: function (data) {
alert(data);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
alert(XMLHttpRequest.status);
alert(errorThrown);
}
});
}
但是,當我把它,我得到一個錯誤500「內部服務器錯誤」
我在Web方法中放置了一個斷點,但沒有達到它。
可能是什麼問題?
感謝
這是我在文章中繼續參考使用jQuery與ASMX Web服務時 - http://encosia.com/using-jquery-to-consume-aspnet-json-網頁服務/。 – jrummell