Specifies that the server type must be generated in the proxy object. This class cannot be inherited.
Syntax
CSharp
VisualBasic
ManagedCPlusPlus
JSharp
Members
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.
noteIf 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
Inheritance Hierarchy
Assembly: System.Web.Extensions (Module: System.Web.Extensions)