加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

WebMethodAttribute 类

发布时间:2020-12-17 02:49:08 所属栏目:安全 来源:网络整理
导读:向使用 ASP.NET 创建的 XML Web services 中的某个方法添加此属性 (Attribute) 后,就可以从远程 Web 客户端调用该方法。无法继承此类。 命名空间: System.Web.Services 程序集: System.Web.Services(在 system.web.services.dll 中) 语法 Visual Basic(
向使用 ASP.NET 创建的 XML Web services 中的某个方法添加此属性 (Attribute) 后,就可以从远程 Web 客户端调用该方法。无法继承此类。

命名空间: System.Web.Services
程序集: System.Web.Services(在 system.web.services.dll 中)

语法
Visual Basic(声明)
<AttributeUsageAttribute(AttributeTargets.Method)> _
Public NotInheritable Class WebMethodAttribute
	Inherits Attribute
Visual Basic (用法)
Dim instance As WebMethodAttribute
C#
[AttributeUsageAttribute(AttributeTargets.Method)] 
public sealed class WebMethodAttribute : Attribute
C++
[AttributeUsageAttribute(AttributeTargets::Method)] 
public ref class WebMethodAttribute sealed : public Attribute
J#
/** @attribute AttributeUsageAttribute(AttributeTargets.Method) */ 
public final class WebMethodAttribute extends Attribute
JScript
AttributeUsageAttribute(AttributeTargets.Method) 
public final class WebMethodAttribute extends Attribute
XAML
?
?

示例

在下面的示例中,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

请参见

参考

WebMethodAttribute 成员
System.Web.Services 命名空间
TransactionOption
WebService
?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读