Specifies which HTTP verb is used to invoke a method and the format of the response. This class cannot be inherited.
Syntax
CSharp
VisualBasic
ManagedCPlusPlus
JSharp
Members
Remarks
The use of the ScriptMethodAttribute attribute is optional, but the method must have the WebMethodAttribute attribute applied to be invoked from ECMAScript (JavaScript). If ScriptMethodAttribute is not included, the method will be called by using the HTTP POST command and the response will be serialized as JavaScript Object Notation (JSON). You cannot override this setting from script. The use of ScriptMethodAttribute should be considered carefully.
ScriptMethodAttribute only takes named parameters. The following are the properties of ScriptMethodAttribute that can be used as named parameters:
UseHttpGet
Specifies whether the method will be invoked by using the HTTP GET command. The default is false. Setting the UseHttpGet property to true might pose a security risk for your application if you are working with sensitive data or transactions.
ResponseFormat
Specifies whether the response will be serialized as JSON or as XML. The default is Json. The ResponseFormat property is useful for scenarios where the return type of the method is XmlDocument or XmlElement.
XmlSerializeString
Specifies whether all return types, including string types, are serialized as XML. The value of the XmlSerializeString property is ignored when the response is serialized as JSON.
For more information about using attributes, see Extending Metadata Using Attributes.
Examples
The following example demonstrates how to apply ScriptMethodAttribute to the GetXmlDocument and EchoStringAndDate methods to specify which HTTP verb to use and the response format.
Permissions
Inheritance Hierarchy
Assembly: System.Web.Extensions (Module: System.Web.Extensions)