Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I would like to know what url should we use on AJAX to call a WebMethod in an external C# class

To call a [WebMethod] on a page's code behind by AJAX we use:

url: 'default.aspx/Method'

But i am being unable to access a [WebMethod] in MyClass.cs (located in /foo/)

Those, for example, don't work:

url: 'default.aspx/MyClass.Method'
url: 'foo/MyClass.cs/Method'

How can i access a WebMethod on an external C# class file?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
278 views
Welcome To Ask or Share your Answers For Others

1 Answer

You need to add a web accessible file to interact with the external classes in order to access them from AJAX calls. You could use something like an asmx (ASP.Net web service) that exposes the webmethods. The file is basically just a markup place holder that points at a class file. Contents are just:

<%@ WebService Language="C#" CodeBehind="~/foo/MyClass.cs" Class="MyClass" %>

Then your class has to inherit from System.Web.Services.WebService and you should be good.

If you do an add file from Visual Studio and add a web service file you can get it to create all this for you.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...