WebMethodAttribute Classe

Definizione

Aggiungendo questo attributo a un metodo in un servizio Web XML creato utilizzando ASP.NET, si consentirà la chiamata del metodo da parte di client Web remoti. La classe non può essere ereditata.

public ref class WebMethodAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Method)]
public sealed class WebMethodAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Method, Inherited=true)]
public sealed class WebMethodAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Method)>]
type WebMethodAttribute = class
    inherit Attribute
[<System.AttributeUsage(System.AttributeTargets.Method, Inherited=true)>]
type WebMethodAttribute = class
    inherit Attribute
Public NotInheritable Class WebMethodAttribute
Inherits Attribute
Ereditarietà
WebMethodAttribute
Attributi

Esempio

Nell'esempio seguente il metodo GetMachineName può essere chiamato in remoto sul Web, perché ha un oggetto WebMethodAttribute. GetUserName non può essere chiamato in modalità remota, perché non ha un WebMethodAttribute, anche se è public.

<%@ WebService Language="C#" Class="Util"%>
    using System;
    using System.Web.Services;
    public class Util: WebService {
       public string GetUserName() {
          return User.Identity.Name;
       }
    
       [ WebMethod(Description="Obtains the Server Machine Name",
       EnableSession=true)]
       public string GetMachineName() {
          return Server.MachineName;
       }
    }
<%@ WebService Language="VB" Class="Util"%>

Imports System
Imports System.Web.Services

Public Class Util
    Inherits WebService
    
    Public Function GetUserName() As String
        Return User.Identity.Name
    End Function    
    
    <WebMethod(Description := "Obtains the Server Machine Name", _
        EnableSession := True)> _
    Public Function GetMachineName() As String
        
        Return Server.MachineName
    End Function
End Class

Commenti

I metodi all'interno di una classe con questo set di attributi sono denominati metodi del servizio Web XML. Il metodo e la classe devono essere pubblici ed eseguiti all'interno di un'applicazione Web ASP.NET.

Costruttori

WebMethodAttribute()

Inizializza una nuova istanza della classe WebMethodAttribute.

WebMethodAttribute(Boolean)

Inizializza una nuova istanza della classe WebMethodAttribute.

WebMethodAttribute(Boolean, TransactionOption)

Inizializza una nuova istanza della classe WebMethodAttribute.

WebMethodAttribute(Boolean, TransactionOption)
WebMethodAttribute(Boolean, TransactionOption, Int32)

Inizializza una nuova istanza della classe WebMethodAttribute.

WebMethodAttribute(Boolean, TransactionOption, Int32)
WebMethodAttribute(Boolean, TransactionOption, Int32, Boolean)

Inizializza una nuova istanza della classe WebMethodAttribute.

WebMethodAttribute(Boolean, TransactionOption, Int32, Boolean)

Proprietà

BufferResponse

Ottiene o imposta la memorizzazione della risposta alla richiesta nel buffer.

CacheDuration

Ottiene o imposta il numero di secondi che indicano la durata del mantenimento della risposta nella cache.

Description

Messaggio descrittivo per il metodo di servizio Web XML.

EnableSession

Indica se lo stato della sessione è attivato per un metodo di servizio Web XML.

MessageName

Il nome utilizzato per il metodo di servizio Web XML nei dati che un metodo di servizio Web XML riceve e restituisce.

TransactionOption

Indica il supporto transazioni di un metodo di servizio Web XML.

TypeId

Quando è implementata in una classe derivata, ottiene un identificatore univoco della classe Attribute.

(Ereditato da Attribute)

Metodi

Equals(Object)

Restituisce un valore che indica se questa istanza è uguale a un oggetto specificato.

(Ereditato da Attribute)
GetHashCode()

Restituisce il codice hash per l'istanza.

(Ereditato da Attribute)
GetType()

Ottiene l'oggetto Type dell'istanza corrente.

(Ereditato da Object)
IsDefaultAttribute()

In caso di override in una classe derivata, indica se il valore di questa istanza è il valore predefinito per la classe derivata.

(Ereditato da Attribute)
Match(Object)

Quando è sottoposto a override in una classe derivata, restituisce un valore che indica se questa istanza equivale a un oggetto specificato.

(Ereditato da Attribute)
MemberwiseClone()

Crea una copia superficiale dell'oggetto Object corrente.

(Ereditato da Object)
ToString()

Restituisce una stringa che rappresenta l'oggetto corrente.

(Ereditato da Object)

Implementazioni dell'interfaccia esplicita

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Esegue il mapping di un set di nomi a un set corrispondente di ID dispatch.

(Ereditato da Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Recupera le informazioni sul tipo relative a un oggetto, che possono essere usate per ottenere informazioni sul tipo relative a un'interfaccia.

(Ereditato da Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Recupera il numero delle interfacce di informazioni sul tipo fornite da un oggetto (0 o 1).

(Ereditato da Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Fornisce l'accesso a proprietà e metodi esposti da un oggetto.

(Ereditato da Attribute)

Si applica a

Vedi anche