나는 다음과 같은 코드로 AEWService.asmx라는 이름의 웹 서비스가 : 나는 아약스와의 WebMethod를 호출 할 때는 ASP.NET은 웹 서비스 내부 webMethods를 호출 - 내부 서버 오류
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace editor
{
[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 AEWService : System.Web.Services.WebService
{
[WebMethod]
public static Dictionary<string, string> TestFunc(string elementToBeModified, string selectedValue)
{
Dictionary<string, string> newValues = new Dictionary<string, string>();
newValues.Add("k1", "val1");
newValues.Add("k2", "val2");
return newValues;
}
}
}
, 나는 500 오류를 - 알 수없는 웹 메소드 인 TestFunc. Ajax 호출은 다음과 같습니다
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
:
var dataString = JSON.stringify({
"elementToBeModified": "someElement",
"selectedValue": "someValue"
});
$.ajax({
url: 'AEWService.asmx/TestFunc',
type: "POST",
data: dataString,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
// do somethig...
}
});
가 나는 또한 (나는 그들이 무슨 뜻인지 모르겠지만 나는 그들이 확인 바랍니다) 태그 아래의 Web.config에 다음 줄을 추가 이 코드는 webmethod가 aspx 페이지에있을 때 완벽하게 작동했습니다. asmx의 문제점은 무엇입니까?
감사합니다.
웹 메서드에 try/catch를 넣고 오류가 발생했는지 확인하십시오. –