在下面的示例中,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; } }
此类型的任何公共静态(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。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。