WebMethod Attribute
As explained previously, a web service is defined by a WebService
class. It is not necessary for the WebService
class to expose all of its methods to consumers of the web service. Each method you do want to expose must do the following:
Be declared as
public
.Have the
WebMethod
attribute placed before the method declaration. (TheWebMethod
attribute comes from theWebMethodAttribute
class, which is contained in theSystem.Web.Services
namespace.)
As you saw in the previous examples in this chapter, the basic WebMethod
attribute looks something like the highlighted code in the following snippet:
[WebMethod]
public string GetName(string StockSymbol)
The WebMethod
attribute has properties that are used to configure the behavior of the specific web method. Here is the syntax:
[WebMethod(PropertyName=value)]
PropertyName
is a valid property accepted by the WebMethod
attribute (these are described below), and value
is the value to be assigned to that property. If there are multiple WebMethod
properties, separate each property/value pair with a comma within a single set of parentheses as in this example:
[WebMethod(BufferResponse=false, Description="Sample description")]
The following sections describe the WebMethod
properties.
The BufferResponse Property
By default, ASP.NET buffers the entire response to a request before sending it from the server to the client. Under most circumstances, this is the optimal behavior. However, if the response is very lengthy, you might want ...
Get Programming ASP.NET, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.