WebMethodAttribute 类
在下面的示例中,GetMachineName 方法因为有 WebMethodAttribute,因此可通过 Web 被远程调用。而 GetUserName 方法因为没有 WebMethodAttribute,因此不能被远程调用,即使它为 public。
Visual Basic
<%@ 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
C#
<%@ 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
此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。
Windows 98,Windows Server 2000 SP4,Windows CE,Windows Millennium Edition,Windows Mobile for Pocket PC,Windows Mobile for Smartphone,Windows Server 2003,Windows XP Media Center Edition,Windows XP Professional x64 Edition,Windows XP SP2,Windows XP Starter Edition ? Windows Vista、Microsoft Windows XP SP2 和 Windows Server 2003 SP1 支持 Microsoft .NET Framework 3.0。 .NET Framework受以下版本支持:3.0、2.0、1.1、1.0.NET Compact Framework受以下版本支持:2.0、1.0参考System.Web.Services 命名空间 TransactionOption WebService (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |