向使用 ASP.NET 创建的 XML Web services 中的某个方法添加此属性 (Attribute) 后,就可以从远程 Web 客户端调用该方法。无法继承此类。
命名空间: System.Web.Services
<script type="text/Javascript"> var ExpCollDivStr = ExpCollDivStr; ExpCollDivStr = ExpCollDivStr + "ctl00_LibFrame_ctl07ccf5527,"; var ExpCollImgStr = ExpCollImgStr; ExpCollImgStr = ExpCollImgStr + "ctl00_LibFrame_ctl07img,"; </script>
语法
|
在下面的示例中,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; } }
<script type="text/Javascript"> var ExpCollDivStr = ExpCollDivStr; ExpCollDivStr = ExpCollDivStr + "ctl00_LibFrame_ctl158cbd9bc,"; var ExpCollImgStr = ExpCollImgStr; ExpCollImgStr = ExpCollImgStr + "ctl00_LibFrame_ctl15img,"; </script>
<script type="text/Javascript"> var ExpCollDivStr = ExpCollDivStr; ExpCollDivStr = ExpCollDivStr + "ctl00_LibFrame_ctl180fe8ccd,"; var ExpCollImgStr = ExpCollImgStr; ExpCollImgStr = ExpCollImgStr + "ctl00_LibFrame_ctl18img,"; </script>
<script type="text/Javascript"> var ExpCollDivStr = ExpCollDivStr; ExpCollDivStr = ExpCollDivStr + "ctl00_LibFrame_ctl21971458d,"; var ExpCollImgStr = ExpCollImgStr; ExpCollImgStr = ExpCollImgStr + "ctl00_LibFrame_ctl21img,"; </script>
继承层次结构
<script type="text/Javascript"> var ExpCollDivStr = ExpCollDivStr; ExpCollDivStr = ExpCollDivStr + "ctl00_LibFrame_ctl2480678ad,"; var ExpCollImgStr = ExpCollImgStr; ExpCollImgStr = ExpCollImgStr + "ctl00_LibFrame_ctl24img,"; </script>
线程安全
此类型的任何公共静态(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。
版本信息
<script type="text/Javascript"> var ExpCollDivStr = ExpCollDivStr; ExpCollDivStr = ExpCollDivStr + "ctl00_LibFrame_ctl25527f550,"; var ExpCollImgStr = ExpCollImgStr; ExpCollImgStr = ExpCollImgStr + "ctl00_LibFrame_ctl25img,"; </script>
<script type="text/Javascript"> var ExpCollDivStr = ExpCollDivStr; ExpCollDivStr = ExpCollDivStr + "ctl00_LibFrame_ctl267f9350b,"; var ExpCollImgStr = ExpCollImgStr; ExpCollImgStr = ExpCollImgStr + "ctl00_LibFrame_ctl26img,"; </script>
<script type="text/Javascript"> var ExpCollDivStr = ExpCollDivStr; ExpCollDivStr = ExpCollDivStr + "ctl00_LibFrame_ctl27ed0dea6,"; var ExpCollImgStr = ExpCollImgStr; ExpCollImgStr = ExpCollImgStr + "ctl00_LibFrame_ctl27img,"; </script>