2011-12-13 1 views
1

나는 다음과 같은 코드로 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의 문제점은 무엇입니까?

감사합니다.

+0

웹 메서드에 try/catch를 넣고 오류가 발생했는지 확인하십시오. –

답변

4

웹 서비스에서 사전 개체를 반환 할 수 없습니다. 이 게시물을 참조하십시오. http://forums.asp.net/t/1370858.aspx/1

또한 정적으로 웹 방법을 표시하지 마십시오. 여기를 확인하십시오 Why are Static Methods not Usable as Web Service Operations in ASMX Web Services?

+0

반환되는 유형에 대한 예외가 발생하면 기뻤습니다. 하지만 문제는 그 함수를 호출 할 수 없다는 것입니다 :) 감사합니다! – VladN

+0

어리석은 ... 나는 aspx에서 WebMethod를 복사/붙여 넣었고 정적에 대해 잊어 버렸습니다 :) 감사합니다. – VladN