.NET Framework Class Library
ScriptServiceAttribute Class

Indicates that a Web service can be invoked from script. This class cannot be inherited.

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

Visual Basic (Declaration)
<AttributeUsageAttribute(AttributeTargets.Class Or AttributeTargets.Interface)> _
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public NotInheritable Class ScriptServiceAttribute _
    Inherits Attribute
Visual Basic (Usage)
Dim instance As ScriptServiceAttribute
C#
[AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Interface)]
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public sealed class ScriptServiceAttribute : Attribute
Visual C++
[AttributeUsageAttribute(AttributeTargets::Class|AttributeTargets::Interface)]
[AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)]
public ref class ScriptServiceAttribute sealed : public Attribute
JScript
public final class ScriptServiceAttribute extends Attribute
Remarks

To invoke a Web service method from ECMAScript (JavaScript), you must apply the ScriptServiceAttribute attribute to the related Web service class. When you apply ScriptServiceAttribute to a Web service class definition that contains one or more methods with WebMethodAttribute applied, the proxy generation script creates a proxy object that corresponds to the Web service class.

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

Examples

The following example demonstrates how to apply ScriptServiceAttribute to the Web service class definition so that its methods can be called from client script.

Visual Basic
<%@ WebService Language="VB" Class="SimpleWebService" %>

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

<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ScriptService()> _
Public Class SimpleWebService
    Inherits System.Web.Services.WebService

    <WebMethod()> _
    Public Function GetServerTime() As String
        Dim serverTime As String = _
         String.Format("The current time is {0}.", DateTime.Now)
        
        Return serverTime
    End Function

End Class
C#
<%@ WebService Language="C#" Class="SimpleWebService" %>

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

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

    [WebMethod]
    public string GetServerTime() 
    {
        string serverTime =
            String.Format("The current time is {0}.", DateTime.Now);

        return serverTime;
    }

}
.NET Framework Security

Inheritance Hierarchy

System..::.Object
  System..::.Attribute
    System.Web.Script.Services..::.ScriptServiceAttribute
Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5
See Also

Reference

Other Resources

Tags :


Page view tracker