0

GetPlaform() javascript 関数内で ajax を使用して GetPlatformNames() webmethod を呼び出そうとしています。
しかし、ajax 呼び出しは決して成功しません。
エラー アラートで、「内部サーバー エラー」メッセージが表示されます。
firebug を使用し、エラーのアラートにブレークポイントを配置しました。request.responstext には次のように記載されています。

 System.InvalidOperationException: GetPlatformNames Web Service method name is not valid.
 at System.Web.Services.Protocols.HttpServerProtocol.Initialize()
 at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, 
  HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing).

これは私が使用しているコードです。
Visual Studio 2012
を使用しています。組み込みの IIS を使用しています。

    namespace XYZ
    {
//// <summary>
/// Summary description for Platform
/// </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. 
[System.Web.Script.Services.ScriptService]
public class Platform : System.Web.Services.WebService
{
    [WebMethod]        
    public static string GetPlatformNames()
    {
        var result ="Hello World";
        return result;
    }
    [WebMethod]
    public static string GetServerTimeString()
    {
        return "Current Server Time: " + DateTime.Now.ToString();
    }
    [WebMethod]
    public static void AddaPlatform(string platforName)
    {
        //Code to insert into database
    }
}   
  }

function GetPlatforms() {  
var param = '{platformName:"'+$("#platformNameInputTextBoxId").val()+'"}';
$.ajax({
    type: 'POST',
    url: 'Platform.asmx/GetPlatformNames',
    statusCode: {
        404: function () {
            alert('Could not contact server.');
        },
        500: function () {
            alert('A server-side error has occurred.');
        }
    },
    success: function (data) {
        alert(data);
    },
    error: function(request,status,error) {
        alert(request.statusText);
    }
});
}
4

1 に答える 1

2

static呼び出している Web メソッドからキーワードを削除してください。それはうまくいくでしょう。

于 2013-02-26T10:52:36.037 に答える