Export (0) Print
Expand All

ScriptMethodAttribute.ResponseFormat Property

Gets or sets the format of the method response.

Namespace:  System.Web.Script.Services
Assembly:  System.Web.Extensions (in System.Web.Extensions.dll)

public ResponseFormat ResponseFormat { get; set; }

Property Value

Type: System.Web.Script.Services.ResponseFormat
One of the ResponseFormat values. The default is Json.

Use the ResponseFormat property when you want to specify XML as the format for the return type. This is useful when the method returns an XmlDocument or an XmlElement object.

When the ResponseFormat property is set to Xml, the public fields and properties of the return type that have the ScriptIgnoreAttribute attribute applied will not be ignored. This is because they will be serialized by using the XmlSerializer object instead of the JavaScriptSerializer object. You must apply the XmlIgnoreAttribute attribute to make XmlSerializer ignore, or skip, those public fields and properties of the return type.

The following example shows how to apply the ScriptMethodAttribute attribute to a Web method with the ResponseFormat property set to Xml. The return value of the method will be serialized as XML and sent to the succeeded callback function as an object of type XmlDocument. This code example is part of a larger example provided for the ScriptMethodAttribute class.

[ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
public XmlDocument GetXmlDocument()
    XmlDocument xmlDoc = new XmlDocument();
    return xmlDoc;

.NET Framework

Supported in: 4.5, 4, 3.5

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

© 2014 Microsoft