WebMethodAttribute コンストラクタ ()とは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > WebMethodAttribute コンストラクタ ()の意味・解説 

WebMethodAttribute コンストラクタ ()

WebMethodAttribute クラス新しインスタンス初期化します。

名前空間: System.Web.Services
アセンブリ: System.Web.Services (system.web.services.dll 内)
構文構文

Dim instance As New WebMethodAttribute
public WebMethodAttribute ()
public:
WebMethodAttribute ()
public WebMethodAttribute ()
public function WebMethodAttribute ()
使用例使用例
<%@ 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> _
    Public Function GetMachineName() As
 String
        
        Return Server.MachineName
    End Function
End Class

<%@ WebService Language="C#" Class="Util"%>
    using System;
    using System.Web.Services;
    public class Util: WebService {
       public string GetUserName() {
          return User.Identity.Name;
       }
    
       [ WebMethod]
       public string GetMachineName() {
          return Server.MachineName;
       }
    }

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
WebMethodAttribute クラス
WebMethodAttribute メンバ
System.Web.Services 名前空間
WebMethodAttribute クラス

WebMethodAttribute コンストラクタ (Boolean, TransactionOption)

WebMethodAttribute クラス新しインスタンス初期化します。

名前空間: System.Web.Services
アセンブリ: System.Web.Services (system.web.services.dll 内)
構文構文

Public Sub New ( _
    enableSession As Boolean, _
    transactionOption As TransactionOption _
)
Dim enableSession As Boolean
Dim transactionOption As TransactionOption

Dim instance As New WebMethodAttribute(enableSession,
 transactionOption)
public WebMethodAttribute (
    bool enableSession,
    TransactionOption transactionOption
)
public:
WebMethodAttribute (
    bool enableSession, 
    TransactionOption transactionOption
)
public WebMethodAttribute (
    boolean enableSession, 
    TransactionOption transactionOption
)
public function WebMethodAttribute (
    enableSession : boolean, 
    transactionOption : TransactionOption
)

パラメータ

enableSession

XML Web サービス メソッドに対してセッション状態が有効かどうか初期化します。

transactionOption

XML Web サービス メソッドトランザクション サポート初期化します。

解説解説

HTTP プロトコルの状態のない性質のため、Web サービス呼び出しは、トランザクションルートにだけなることができます。したがって次の 2 つ設定等価で、それぞれの呼び出し新しトランザクション作成します

[WebMethod(TransactionOption = TransactionOption.Required)]
[WebMethod(TransactionOption = TransactionOption.RequiresNew)]

また、次のすべての設定等価で、トランザクションサポートされていないことを意味します

[WebMethod] // TransactionOption.Disabled is the default
[WebMethod(TransactionOption = TransactionOption.Disabled)]
[WebMethod(TransactionOption = Transaction.NotSupported)]
[WebMethod(TransactionOption = Transaction.Supported)]
使用例使用例
<%@ WebService Language="VB" Class="Bank"%>
<%@ assembly name="System.EnterpriseServices,Version=1.0.3300.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a"
 %>
 
Imports System
Imports System.Web.Services
Imports System.EnterpriseServices

Public Class Bank
    Inherits WebService    
    
    <WebMethod(True,TransactionOption.RequiresNew)> _  
  
    Public Sub Transfer(Amount As
 Long, AcctNumberTo As Long,
 _
        AcctNumberFrom As Long)
        
        Dim objBank As New
 MyCOMObject()
        
        If objBank.GetBalance(AcctNumberFrom) < Amount Then
            ' Explicitly end the transaction.
            ContextUtil.SetAbort()
        Else
            ' The Credit and Debit methods explictly determine, in their
            ' own code, whether to commit or end the transaction.
            objBank.Credit(Amount, AcctNumberTo)
            objBank.Debit(Amount, AcctNumberFrom)
        End If
    End Sub
End Class
      
<%@ WebService Language="C#" Class="Bank"%>
<%@ assembly name="System.EnterpriseServices,Version=1.0.3300.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a"
 %>
 
using System;
using System.Web.Services;
using System.EnterpriseServices;

public class Bank : WebService 
{

    [ WebMethod(true,TransactionOption.RequiresNew) ]
    public void Transfer(long Amount, long
 AcctNumberTo, long AcctNumberFrom)  
    { 
        MyCOMObject objBank = new MyCOMObject();
 
        if (objBank.GetBalance(AcctNumberFrom) < Amount )
            // Explicitly end the transaction.
            ContextUtil.SetAbort();
        else 
        {
            // The Credit and Debit methods explictly determine, in
 their
            // own code, whether to commit or end the transaction.
            objBank.Credit(Amount, AcctNumberTo);
            objBank.Debit(Amount, AcctNumberFrom);
        }
    }
}
      
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
WebMethodAttribute クラス
WebMethodAttribute メンバ
System.Web.Services 名前空間

WebMethodAttribute コンストラクタ

WebMethodAttribute クラス新しインスタンス初期化します。
オーバーロードの一覧オーバーロードの一覧

名前 説明
WebMethodAttribute () WebMethodAttribute クラス新しインスタンス初期化します。

.NET Compact Framework によってサポートされています。

WebMethodAttribute (Boolean) WebMethodAttribute クラス新しインスタンス初期化します。
WebMethodAttribute (Boolean, TransactionOption) WebMethodAttribute クラス新しインスタンス初期化します。
WebMethodAttribute (Boolean, TransactionOption, Int32) WebMethodAttribute クラス新しインスタンス初期化します。
WebMethodAttribute (Boolean, TransactionOption, Int32, Boolean) WebMethodAttribute クラス新しインスタンス初期化します。
参照参照

関連項目

WebMethodAttribute クラス
WebMethodAttribute メンバ
System.Web.Services 名前空間
WebMethodAttribute クラス

WebMethodAttribute コンストラクタ (Boolean, TransactionOption, Int32, Boolean)

WebMethodAttribute クラス新しインスタンス初期化します。

名前空間: System.Web.Services
アセンブリ: System.Web.Services (system.web.services.dll 内)
構文構文

Public Sub New ( _
    enableSession As Boolean, _
    transactionOption As TransactionOption, _
    cacheDuration As Integer, _
    bufferResponse As Boolean _
)
Dim enableSession As Boolean
Dim transactionOption As TransactionOption
Dim cacheDuration As Integer
Dim bufferResponse As Boolean

Dim instance As New WebMethodAttribute(enableSession,
 transactionOption, cacheDuration, bufferResponse)
public WebMethodAttribute (
    bool enableSession,
    TransactionOption transactionOption,
    int cacheDuration,
    bool bufferResponse
)
public:
WebMethodAttribute (
    bool enableSession, 
    TransactionOption transactionOption, 
    int cacheDuration, 
    bool bufferResponse
)
public WebMethodAttribute (
    boolean enableSession, 
    TransactionOption transactionOption, 
    int cacheDuration, 
    boolean bufferResponse
)
public function WebMethodAttribute (
    enableSession : boolean, 
    transactionOption : TransactionOption, 
    cacheDuration : int, 
    bufferResponse : boolean
)

パラメータ

enableSession

XML Web サービス メソッドに対してセッション状態が有効かどうか初期化します。

transactionOption

XML Web サービス メソッドトランザクション サポート初期化します。

cacheDuration

応答キャッシュされる秒数を初期化します。

bufferResponse

この要求対す応答バッファリングされるかどうか初期化します。

解説解説

HTTP プロトコルの状態のない性質のため、Web サービス呼び出しは、トランザクションルートみになることができます。したがって次の 2 つ設定等価で、それぞれの呼び出し新しトランザクション作成します

[WebMethod(TransactionOption = TransactionOption.Required)]
[WebMethod(TransactionOption = TransactionOption.RequiresNew)]

また、次のすべての設定等価で、トランザクションサポートされていないことを意味します

[WebMethod] // TransactionOption.Disabled is the default
[WebMethod(TransactionOption = TransactionOption.Disabled)]
[WebMethod(TransactionOption = Transaction.NotSupported)]
[WebMethod(TransactionOption = Transaction.Supported)]
使用例使用例
<%@WebService Class="Streaming"
 language="VB"%>
<%@ assembly name="System.EnterpriseServices,Version=1.0.3300.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a"
 %>

Imports System
Imports System.IO
Imports System.Collections
Imports System.Xml.Serialization
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.EnterpriseServices

Public Class Streaming 

    <WebMethod(True,TransactionOption.NotSupported,60,False)>
 _
    Public Function GetTextFile(filename As
 String ) As TextFile
      Return New TextFile(filename)       
 
    End Function

    <WebMethod> _
    Public Sub CreateTextFile(contents As
 TextFile) 
        contents.Close()
    End Sub

End Class

Public Class TextFile 
    Public filename As String
 
    Private readerWriter As TextFileReaderWriter
 

    Public Sub New() 
    End Sub

    Public Sub New(filename
 As String) 
        Me.filename = filename
    End Sub

    <XmlArrayItem("line")> _
    Public ReadOnly Property
 contents As TextFileReaderWriter
        Get 
            readerWriter = New TextFileReaderWriter(filename)
            Return readerWriter
        End Get
    End Property

    Public Sub Close() 
        If Not (readerWriter Is
 Nothing) Then
      readerWriter.Close()
        End If
    End Sub
End Class

Public Class TextFileReaderWriter 
   Implements IEnumerable 


    Public Filename As String
 
    Private writer As StreamWriter 

    Public Sub New() 
    End Sub

    Public Sub New(myfilename
 As String ) 
        Filename = myfilename
    End Sub

    Function GetEnumerator() As IEnumerator
 Implements IEnumerable.GetEnumerator
        Dim reader As StreamReader = New
 StreamReader(Filename)
        Return New TextFileEnumerator(reader)
    End Function

    Public Sub Add(line As
 String) 
        If (writer Is Nothing)
 Then
            writer = New StreamWriter(Filename)
    End If
        writer.WriteLine(line)
    End Sub

    Public Sub Add(obj as
 Object)
    
    End Sub

    Public Sub Close() 
        If Not (writer Is
 Nothing) Then writer.Close()
    End Sub

End Class

Public Class TextFileEnumerator 
  Implements IEnumerator 
    Private currentLine As String
    Private reader As StreamReader

    Public Sub New(reader
 As StreamReader) 
        Me.reader = reader
    End Sub

    Public Function MoveNext() As
 Boolean Implements IEnumerator.MoveNext
        currentLine = reader.ReadLine()
        If (currentLine Is Nothing)
 Then
            reader.Close()
            Return False
        Else
            Return True
        End If
    End Function

    Public Sub Reset() Implements
 IEnumerator.Reset
        reader.BaseStream.Position = 0
    End Sub

    ReadOnly Property Current As
 object Implements IEnumerator.Current
        Get 
            Return CurrentLine
        End Get
    End Property
End Class
<%@WebService class="Streaming" language="C#"%>
<%@ assembly name="System.EnterpriseServices,Version=1.0.3300.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a"
 %>

using System;
using System.IO;
using System.Collections;
using System.Xml.Serialization;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.EnterpriseServices;

public class Streaming {

    [WebMethod(true,TransactionOption.NotSupported,60,false)]
    public TextFile GetTextFile(string filename)
 {
        return new TextFile(filename);
    }

    [WebMethod]
    public void CreateTextFile(TextFile contents)
 {
        contents.Close();
    }

}

public class TextFile {
    public string filename;
    private TextFileReaderWriter readerWriter;

    public TextFile() {
    }

    public TextFile(string filename) {
        this.filename = filename;
    }

    [XmlArrayItem("line")]
    public TextFileReaderWriter contents {
        get {
            readerWriter = new TextFileReaderWriter(filename);
            return readerWriter;
        }
    }

    public void Close() {
        if (readerWriter != null) readerWriter.Close();
    }
}

public class TextFileReaderWriter : IEnumerable
 {

    public string Filename;
    private StreamWriter writer;

    public TextFileReaderWriter() {
    }

    public TextFileReaderWriter(string filename)
 {
        Filename = filename;
    }

    public TextFileEnumerator GetEnumerator() {
        StreamReader reader = new StreamReader(Filename);
        return new TextFileEnumerator(reader);
    }

    IEnumerator IEnumerable.GetEnumerator() {
        return GetEnumerator();
    }

    public void Add(string
 line) {
        if (writer == null)
            writer = new StreamWriter(Filename);
        writer.WriteLine(line);
    }

    public void Close() {
        if (writer != null) writer.Close();
    }

}

public class TextFileEnumerator : IEnumerator
 {
    private string currentLine;
    private StreamReader reader;

    public TextFileEnumerator(StreamReader reader) {
        this.reader = reader;
    }

    public bool MoveNext() {
        currentLine = reader.ReadLine();
        if (currentLine == null) {
            reader.Close();
            return false;
        }
        else
            return true;
    }

    public void Reset() {
        reader.BaseStream.Position = 0;
    }

    public string Current {
        get {
            return currentLine;
        }
    }

    object IEnumerator.Current {
        get {
            return Current;
        }
    }
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
WebMethodAttribute クラス
WebMethodAttribute メンバ
System.Web.Services 名前空間

WebMethodAttribute コンストラクタ (Boolean)

WebMethodAttribute クラス新しインスタンス初期化します。

名前空間: System.Web.Services
アセンブリ: System.Web.Services (system.web.services.dll 内)
構文構文

Public Sub New ( _
    enableSession As Boolean _
)
Dim enableSession As Boolean

Dim instance As New WebMethodAttribute(enableSession)
public WebMethodAttribute (
    bool enableSession
)
public:
WebMethodAttribute (
    bool enableSession
)
public WebMethodAttribute (
    boolean enableSession
)
public function WebMethodAttribute (
    enableSession : boolean
)

パラメータ

enableSession

XML Web サービス メソッドに対してセッション状態が有効かどうか初期化します。

使用例使用例
<%@ WebService Language="VB" Class="Util"
 %>
 
Imports System.Web.Services

Public Class Util
    Inherits WebService
    
    <WebMethod(True)> _
    Public Function SessionHitCounter() As
 Integer
        
        If Session("HitCounter")
 Is Nothing Then
            Session("HitCounter") = 1
        Else
            Session("HitCounter") = CInt(Session("HitCounter"))
 + 1
        End If
        Return CInt(Session("HitCounter"))
    End Function
End Class

<%@ WebService Language="C#" Class="Util" %>
 
 using System.Web.Services;
 
 public class Util: WebService {
   [ WebMethod(true)]
    public int SessionHitCounter() {
       if (Session["HitCounter"] == null)
 {
          Session["HitCounter"] = 1;
       }
       else {
          Session["HitCounter"] = ((int) Session["HitCounter"])
 + 1;
          }
       return ((int) Session["HitCounter"]);
    }   
 }

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
WebMethodAttribute クラス
WebMethodAttribute メンバ
System.Web.Services 名前空間

WebMethodAttribute コンストラクタ (Boolean, TransactionOption, Int32)

WebMethodAttribute クラス新しインスタンス初期化します。

名前空間: System.Web.Services
アセンブリ: System.Web.Services (system.web.services.dll 内)
構文構文

Public Sub New ( _
    enableSession As Boolean, _
    transactionOption As TransactionOption, _
    cacheDuration As Integer _
)
Dim enableSession As Boolean
Dim transactionOption As TransactionOption
Dim cacheDuration As Integer

Dim instance As New WebMethodAttribute(enableSession,
 transactionOption, cacheDuration)
public WebMethodAttribute (
    bool enableSession,
    TransactionOption transactionOption,
    int cacheDuration
)
public:
WebMethodAttribute (
    bool enableSession, 
    TransactionOption transactionOption, 
    int cacheDuration
)
public WebMethodAttribute (
    boolean enableSession, 
    TransactionOption transactionOption, 
    int cacheDuration
)
public function WebMethodAttribute (
    enableSession : boolean, 
    transactionOption : TransactionOption, 
    cacheDuration : int
)

パラメータ

enableSession

XML Web サービス メソッドに対してセッション状態が有効かどうか初期化します。

transactionOption

XML Web サービス メソッドトランザクション サポート初期化します。

cacheDuration

応答キャッシュされる秒数を初期化します。

解説解説

HTTP プロトコルの状態のない性質のため、Web サービス呼び出しは、トランザクションルートにだけなることができます。したがって次の 2 つ設定等価で、それぞれの呼び出し新しトランザクション作成します

[WebMethod(TransactionOption = TransactionOption.Required)]
[WebMethod(TransactionOption = TransactionOption.RequiresNew)]

また、次のすべての設定等価で、トランザクションサポートされていないことを意味します

[WebMethod] // TransactionOption.Disabled is the default
[WebMethod(TransactionOption = TransactionOption.Disabled)]
[WebMethod(TransactionOption = Transaction.NotSupported)]
[WebMethod(TransactionOption = Transaction.Supported)]
使用例使用例
<%@ WebService Language="VB" Class="Counter"
 %>
<%@ assembly name="System.EnterpriseServices,Version=1.0.3300.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a"
 %>

Imports System.Web.Services
Imports System
Imports System.Web
Imports System.EnterpriseServices

Public Class Counter
    Inherits WebService  

    <WebMethod(true,TransactionOption.NotSupported,60)>
 _
    Public Function ServiceUsage() As
 Integer
        
        ' If the XML Web service has not been accessed, initialize it
 to 1.
        If Application("MyServiceUsage")
 Is Nothing Then
            Application("MyServiceUsage") = 1
        Else
            ' Increment the usage count.
            Application("MyServiceUsage") = CInt(Application("MyServiceUsage"))
 + 1
        End If
        
        ' Return the usage count.
        Return CInt(Application("MyServiceUsage"))
    End Function
End Class

<%@ WebService Language="C#" Class="Counter" %>
<%@ assembly name="System.EnterpriseServices,Version=1.0.3300.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a"
 %>

using System.Web.Services;
using System;
using System.Web;
using System.EnterpriseServices;

public class Counter : WebService {
     
     [ WebMethod(true,TransactionOption.NotSupported,60) ]
     public int ServiceUsage() {
          // If the XML Web service has not been accessed, initialize
 it to 1.
          if (Application["MyServiceUsage"] == null)
 {
              Application["MyServiceUsage"] = 1;
          }
          else {
              // Increment the usage count.
              Application["MyServiceUsage"] = ((int)
 Application["MyServiceUsage"]) + 1;
          }

          // Return the usage count.     
          return  (int) Application["MyServiceUsage"];
     }
}

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
WebMethodAttribute クラス
WebMethodAttribute メンバ
System.Web.Services 名前空間



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「WebMethodAttribute コンストラクタ ()」の関連用語

WebMethodAttribute コンストラクタ ()のお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



WebMethodAttribute コンストラクタ ()のページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS