クリックして評価とフィードバックをお寄せください
MSDN
MSDN ライブラリ
.NET 開発
.NET Framework 3.5
.NET Framework 3.5
System.Web.Services 名前空間
WebMethodAttribute クラス

  低帯域幅での表示をオンにする
このページは次のバージョンについて記述しています。
Microsoft Visual Studio 2008/.NET Framework 3.5

その他のバージョンについては、以下の情報を参照してください。
.NET Framework クラス ライブラリ
WebMethodAttribute クラス

更新 : 2007 年 11 月

ASP.NET で作成された XML Web サービス内でこの属性をメソッドに追加すると、リモートの 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
Visual C++
[AttributeUsageAttribute(AttributeTargets::Method)]
public ref class WebMethodAttribute sealed : public Attribute
J#
/** @attribute AttributeUsageAttribute(AttributeTargets.Method) */
public final class WebMethodAttribute extends Attribute
JScript
public final class WebMethodAttribute extends Attribute

この属性が設定されているクラス内のメソッドは、XML Web サービス メソッドと呼ばれます。このメソッドとクラスはパブリックとして指定し、ASP.NET Web アプリケーション内部で実行する必要があります。

WebMethodAttribute が設定されているためメソッド GetMachineName を Web 経由でリモートから呼び出すことができる例を次に示します。GetUserNamepublic ですが、WebMethodAttribute が設定されていないためリモートから呼び出すことはできません。

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
この型のすべてのパブリック static (Visual Basic では Shared) メンバは、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。

Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC

.NET Framework および .NET Compact Framework では、各プラットフォームのすべてのバージョンはサポートしていません。サポートされているバージョンについては、「.NET Framework システム要件」を参照してください。

.NET Framework

サポート対象 : 3.5、3.0、2.0、1.1、1.0

.NET Compact Framework

サポート対象 : 3.5、2.0、1.0
コミュニティ コンテンツ   コミュニティ コンテンツとは
新しいコンテンツの追加 RSS  注釈
Processing
© 2009 Microsoft Corporation. All rights reserved. 使用条件  |  商標  |  プライバシー
Page view tracker