This documentation is archived and is not being maintained.
WebMethodAttribute Constructor
.NET Framework 1.1
Initializes a new instance of the WebMethodAttribute class.
Overload List
Initializes a new instance of the WebMethodAttribute class.
Supported by the .NET Compact Framework.
[Visual Basic] Public Sub New()
[C#] public WebMethodAttribute();
[C++] public: WebMethodAttribute();
[JScript] public function WebMethodAttribute();
Initializes a new instance of the WebMethodAttribute class.
[Visual Basic] Public Sub New(Boolean)
[C#] public WebMethodAttribute(bool);
[C++] public: WebMethodAttribute(bool);
[JScript] public function WebMethodAttribute(Boolean);
Initializes a new instance of the WebMethodAttribute class.
[Visual Basic] Public Sub New(Boolean, TransactionOption)
[C#] public WebMethodAttribute(bool, TransactionOption);
[C++] public: WebMethodAttribute(bool, TransactionOption);
[JScript] public function WebMethodAttribute(Boolean, TransactionOption);
Initializes a new instance of the WebMethodAttribute class.
[Visual Basic] Public Sub New(Boolean, TransactionOption, Integer)
[C#] public WebMethodAttribute(bool, TransactionOption, int);
[C++] public: WebMethodAttribute(bool, TransactionOption, int);
[JScript] public function WebMethodAttribute(Boolean, TransactionOption, int);
Initializes a new instance of the WebMethodAttribute class.
[Visual Basic] Public Sub New(Boolean, TransactionOption, Integer, Boolean)
[C#] public WebMethodAttribute(bool, TransactionOption, int, bool);
[C++] public: WebMethodAttribute(bool, TransactionOption, int, bool);
[JScript] public function WebMethodAttribute(Boolean, TransactionOption, int, Boolean);
Example
[Visual Basic, C#] Note This example shows how to use one of the overloaded versions of the WebMethodAttribute constructor. For other examples that might be available, see the individual overload topics.
[Visual Basic] <%@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 [C#] <%@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; } } }
[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button
in the upper-left corner of the page.
See Also
WebMethodAttribute Class | WebMethodAttribute Members | System.Web.Services Namespace
Show: