Questions tagged [webmethod]

WebMethod is an attribute that is marked to indicate that a function (usually in .NET) in a web service is exposed to the consumers of the web service.

The WebMethod attribute is attached to a public method (cannot be attached to a private/protected) that you want the method exposed as part of the .NET Web service. It is also used to further configure the behavior of the method by passing additional attributes. Check out the MSDN link for more information, How to: Use the WebMethod Attribute.

1317 questions
111
votes
12 answers

"Invalid JSON primitive" in Ajax processing

I am getting an error in an ajax call from jQuery. Here is my jQuery function: function DeleteItem(RecordId, UId, XmlName, ItemType, UserProfileId) { var obj = { RecordId: RecordId, UserId: UId, UserProfileId:…
Radhi
  • 6,289
  • 15
  • 47
  • 68
63
votes
13 answers

ASP.NET Calling WebMethod with jQuery AJAX "401 (Unauthorized)"

Been stuck with this for hours {"Message":"Authentication failed.","StackTrace":null,"ExceptionType":"System.InvalidOperationException"} I'm trying to call this WebMethod in my ASP.Net Webform [WebMethod] public static string GetClients(string…
Daniel Cardenas
  • 2,826
  • 2
  • 19
  • 17
42
votes
8 answers

How to call an ASP.NET WebMethod in a UserControl (.ascx)

Is it possible to place a WebMethod in an ascx.cs file (for a UserControl) and then call it from client-side jQuery code? For some reasons I can't place the WebMethod code in an .asmx or .aspx file. Example: In ArticleList.ascx.cs I have the…
gruber
  • 28,739
  • 35
  • 124
  • 216
29
votes
1 answer

Webmethods with HttpContext.Current.User.Identity.IsAuthenticated stop working after inactivity on Azure

I'm testing the Azure server with pages that use Ajax(json)/Webmethod functions. Some of those functions check HttpContext.Current.User.Identity.IsAuthenticated before they run code. Unfortunately, if a user is logged in and the page doesn't make a…
Gloria
  • 1,305
  • 5
  • 22
  • 57
28
votes
5 answers

Calling a 'WebMethod' with jQuery in ASP.NET WebForms

I've set a breakpoint in the following WebMethod but I'm never hitting the breakpoint. cs: [WebMethod] public static string search() { return "worked"; } aspx: function search() { $.ajax({ type: "POST", url:…
marknery
  • 1,533
  • 3
  • 19
  • 27
27
votes
3 answers

The length of the string exceeds the value set on the maxJsonLength property

I am loading tab content data through jQuery's ajax post method via web method with around 200-300 records. And getting following error in the console: Error: Sys.Net.WebServiceFailedException: Sys.Net.WebServiceFailedException:…
swpnilprakashpatil
  • 291
  • 1
  • 4
  • 6
19
votes
8 answers

Call non-static method in server-side from client-side using JavsScript

How do I call a non-static method in server side(aspx.cs) from client side using javascript (aspx)....? As far as I know I can call static method in server side from client side... server side: [WebMethod] public static void method1() { …
Pramulia
  • 191
  • 1
  • 1
  • 3
18
votes
6 answers

Catching errors from calling ASP.NET WebMethod with malformed Json

We have an older ASP.NET WebForms application which performs AJAX request by using jQuery $.ajax() calls on the client side, calling static methods in the page code-behind decorated with [WebMethod] attributes. If an unhandled exception occurs…
Carson63000
  • 4,215
  • 2
  • 24
  • 38
18
votes
2 answers

Authentication failed during call webmethod from jquery.ajx with AspNet.FriendlyUrls and AspNet.Identity

If I call webmethod from jQuery.Ajax with installed Nuget packages Microsoft.AspNet.FriendlyUrls v 1.0.2 and Microsoft.AspNet.Identity v.1.0.0., then I get the data object, but without data.d but with property Message 'Authentication failed'. My…
user3001838
  • 183
  • 1
  • 1
  • 4
18
votes
8 answers

How to call webmethod in Asp.net C#

I want to call a web method in asp.net c# application using the following code Jquery: jQuery.ajax({ url: 'AddToCart.aspx/AddTo_Cart', type: "POST", data: "{'quantity' : " + total_qty + ",'itemId':" + itemId + "}", contentType:…
Balwant Chaudhary
  • 199
  • 1
  • 1
  • 8
18
votes
3 answers

Calling a WebMethod using jQueryAjax "GET"

i have a ajax request which works well using "POST" but when used "GET" it gives me the following error, {"Message":"An attempt was made to call the method \u0027GetSomething\u0027 using a GET request, which is not allowed.","StackTrace":" at…
Vishal Gowda
  • 511
  • 1
  • 3
  • 11
16
votes
2 answers

Pass a user defined object to ASP.NET Webmethod from jQuery, using JSON

I am trying to pass in some simple JSON to an ASP.NET 4.5 Webmethod from jQuery. And it is not working quite the way I want it. It works if I accept the inputs as separate parameters: [WebMethod] public static Address GetJSonAddress(string name,…
Thomas O.
  • 161
  • 1
  • 1
  • 4
15
votes
1 answer

Why WebMethod declared as Static?

I declared a WebMethod in my default.aspx.cs file.. [WebMethod] public static void ResetDate() { LoadCallHistory(TheNewDate.Date); } Why must the WebMethod method be declared static?
Gaurav Gupta
  • 491
  • 3
  • 7
  • 20
14
votes
1 answer

How to return multiple values from a webservice?

I am very new to the world of web services so please bear with me. I am creating a very simple web service in Visual Studio 2010 using .asmx files. Here is the code I am using: namespace MyWebService { [WebService(Namespace =…
Baxter
  • 5,633
  • 24
  • 69
  • 105
13
votes
2 answers

Why Can WebMethod Access Session State Without EnableSessionState?

I have a method on a page marked as a [WebMethod] that uses some session state as part of its operation. After I wrote this code, I suddenly had a flash of memory that you need to use EnableSessionState when you use session state in a [WebMethod]…
user12861
  • 2,358
  • 4
  • 23
  • 41
1
2 3
87 88