Cuando este atributo se agrega a un método en un servicios Web XML creado mediante ASP.NET, el método se puede invocar desde clientes Web remotos. No se puede heredar esta clase.
Espacio de nombres: System.Web.Services
Ensamblado: System.Web.Services (en system.web.services.dll)
Visual Basic (Declaración)
<AttributeUsageAttribute(AttributeTargets.Method)> _
Public NotInheritable Class WebMethodAttribute
Inherits Attribute
Dim instance As WebMethodAttribute
[AttributeUsageAttribute(AttributeTargets.Method)]
public sealed class WebMethodAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Method)]
public ref class WebMethodAttribute sealed : public Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Method) */
public final class WebMethodAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.Method)
public final class WebMethodAttribute extends Attribute
Los métodos de una clase que tenga este atributo establecido se denominan métodos de servicio Web XML. El método y la clase deben ser públicos, y deben ejecutarse dentro de una aplicación Web ASP.NET.
En el siguiente ejemplo, se puede llamar al método GetMachineName de forma remota a través del Web, porque tiene un objeto WebMethodAttribute. No se puede llamar a GetUserName de forma remota, porque no tiene un objeto WebMethodAttribute, aunque sea public.
<%@ 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
<%@ 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;
}
}
System.Object
System.Attribute
System.Web.Services.WebMethodAttribute
Seguridad para subprocesos
Los miembros estáticos públicos (Shared en Visual Basic) de este tipo son seguros para la ejecución de subprocesos. No se garantiza que los miembros de instancias sean seguros para la ejecución de subprocesos.
Windows 98, Windows 2000 Service Pack 4, Windows CE, Windows Millennium, Windows Mobile para Pocket PC, Windows Mobile para Smartphone, Windows Server 2003, Windows XP Media Center, Windows XP Professional x64, Windows XP SP2, Windows XP Starter
Microsoft .NET Framework 3.0 es compatible con Windows Vista, Microsoft Windows XP SP2 y Windows Server 2003 SP1.
.NET Framework
Compatible con: 3.0, 2.0, 1.1, 1.0
.NET Compact Framework
Compatible con: 2.0, 1.0