次の方法で共有


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;
        }
    }
}

プラットフォーム

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

Microsoft .NET Framework 3.0 は Windows Vista,Microsoft Windows XP SP2,および Windows Server 2003 SP1 でサポートされています。

バージョン情報

.NET Framework

サポート対象 : 3.0,2.0,1.1,1.0

参照

関連項目

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