Documentation for: ASP.NET Ajax Version 1.0

This documentation is for a previous version. For the current released version, see the ASP.NET Ajax documentation on MSDN.

 

 

 

 

 

 

 

GenerateScriptTypeAttribute Class

Specifies that the server type must be generated in the proxy object. This class cannot be inherited.

Syntax

CSharp

[AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Method|AttributeTargets.Interface, AllowMultiple = true)]
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public sealed class GenerateScriptTypeAttribute : Attribute

VisualBasic

<AttributeUsageAttribute(AttributeTargets.Class Or AttributeTargets.Method Or AttributeTargets.Interface, AllowMultiple := True)> _
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public NotInheritable Class GenerateScriptTypeAttribute _
	Inherits Attribute

ManagedCPlusPlus

[AttributeUsageAttribute(AttributeTargets::Class|AttributeTargets::Method|AttributeTargets::Interface, AllowMultiple = true)]
[AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)]
public ref class GenerateScriptTypeAttribute sealed : public Attribute

JSharp

/** @attribute AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Method|AttributeTargets.Interface, AllowMultiple = true) */
/** @attribute AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal) */
public final class GenerateScriptTypeAttribute extends Attribute

Members

IconMemberDescription
GenerateScriptTypeAttributeNew(Type)Initializes a new instance of the GenerateScriptTypeAttribute class for the specified type.
Equals(Object)Returns a value that indicates whether this instance is equal to a specified object. (Inherited from Attribute.)
Finalize()Allows an Object to attempt to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
GetHashCode()Returns the hash code for this instance. (Inherited from Attribute.)
GetType()Gets the Type of the current instance. (Inherited from Object.)
IsDefaultAttribute()When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class. (Inherited from Attribute.)
Match(Object)When overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (Inherited from Attribute.)
MemberwiseClone()Creates a shallow copy of the current Object. (Inherited from Object.)
ScriptTypeIdGets or sets the type identifier for the type metadata marker.
ToString()Returns a String that represents the current Object. (Inherited from Object.)
TypeGets the type that is included in the proxy object.
TypeIdWhen implemented in a derived class, gets a unique identifier for this Attribute. (Inherited from Attribute.)

Remarks

Microsoft ASP.NET 2.0 AJAX Extensions automatically generates proxy objects for top-level types corresponding to the input parameters and return values of Web methods in a Web service class that contains the ScriptServiceAttribute attribute. In all the other cases, if you have to generate proxy objects for server types, GenerateScriptTypeAttribute must be applied to the Web service itself or to any Web service method or static page method that has WebMethodAttribute applied.

One or more instances of GenerateScriptTypeAttribute can be applied to a Web service class or method. Microsoft ASP.NET 2.0 AJAX Extensions will then generate an ECMAScript (JavaScript) proxy for each top-level type referenced by each declaration of GenerateScriptTypeAttribute.

note

If you want to generate proxy objects for nested types, you must apply GenerateScriptTypeAttribute to each nested type, also. This is because Microsoft ASP.NET 2.0 AJAX Extensions generates proxies only for top-level types and does not recur.

For more information about using attributes, see Extending Metadata Using Attributes.

Examples

The following example demonstrates how to apply GenerateScriptTypeAttribute to a Web service class and to a Web method in order to include the ColorObject type and its nested type FavoriteColors in the proxy object.

CS

<%@ WebService Language="C#" Class="Samples.AspNet.ColorService" %>

using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;

namespace Samples.AspNet
{

    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ScriptService]
    [GenerateScriptType(typeof(FavoriteColors))]
    public class ColorService : System.Web.Services.WebService
    {

        [GenerateScriptType(typeof(ColorObject), 
            ScriptTypeId = "Color")]
        [WebMethod]
        public string[] GetDefaultColor()
        {
            // Instantiate the default color object.
            ColorObject co = new ColorObject();

            return co.rgb;
        }

        [WebMethod]
        public string EchoDefaultColor()
        {
            // Instantiate the default color object.
            ColorObject co = new ColorObject();

            return co.defaultColor.ToString();
        }
    }

    public class ColorObject
    {
        public string[] rgb =
            new string[] { "00", "00", "FF" };
        public FavoriteColors defaultColor = FavoriteColors.Blue;
    }

    public enum FavoriteColors
    {
        Black,
        White,
        Blue,
        Red
    }
}

VB

<%@ WebService Language="VB" Class="Samples.AspNet.ColorService" %>

Imports System
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Web.Script.Services

Namespace Samples.AspNet

    <WebService([Namespace]:="http://tempuri.org/")> _
    <WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
    <ScriptService()> _
    <GenerateScriptType(GetType(FavoriteColors))> _
    Public Class ColorService
        Inherits System.Web.Services.WebService

        <GenerateScriptType(GetType(ColorObject), ScriptTypeId:="Color")> _
        <WebMethodAttribute()> _
        Public Function GetDefaultColor() As String()
            ' Instantiate the default color object.
            Dim co As New ColorObject()

            Return co.RGB

        End Function

        <WebMethod()> _
        Public Function EchoFavoriteColor() As String
            ' Instantiate the default color object.
            Dim co As New ColorObject()

            Return co.defaultColor.ToString()

        End Function
    End Class 'EmployeeService

    Public Class ColorObject
        Public rgb() As String = {"00", "00", "FF"}
        Public defaultColor As FavoriteColors = FavoriteColors.Blue
    End Class

    Public Enum FavoriteColors
        Black
        White
        Blue
        Red
    End Enum
End Namespace

Permissions

  • AspNetHostingPermission

    for operating in a hosted environment. Demand value: LinkDemand. Associated enumeration: Minimal.

Inheritance Hierarchy

Object

Assembly: System.Web.Extensions (Module: System.Web.Extensions)