Author: zfive5 (zhaozidong) email: zfive5@yahoo.com.cn
WebMethod has 6 attributes: .description.enableness.MessageName.TransactionOption.Cachenure.bufferResponse
1) DESCRIPTION:
It is the information describing the WebService method. Just like the functional comment of the webservice method, you can make the comment that the caller can see.
C #:
[WebMethod (Description = "Author: zfive5 function: hello world")] public string helloworld () {return "hello world";}
WSDL:
-
Indicates whether WebService does not start the session flag, mainly through cookie, default false.
C #:
Public static int i = 0; [WebMethod (EnableSession = true)] public int count () {i = i 1; returni i;}
Enter: http://localhost/webservice1/service1.asmx/count?
Take a look
... XML Version = "1.0" encoding = "uTF-8"?> The first method is accessed by count, and the second method is accessed through count1! 4) TransactionOption: Indicates transaction support for the XML Web Services method. This is the explanation in MSDN: Due to the stateless characteristics of the HTTP protocol, the XML Web Services method can only participate in the transaction as a root object. If the COM object is involved in the same transaction with the XML Web Services method, and the XML Web Services method can call these COM objects in the Component Service Management Tool. If a TransactionOption property is the XML Web Services method for the Required or RequiresNew call another TransactionOption property as the XML Web Services method of the Required or RequiresNew, each XML Web Services method will participate in their own transactions because the XML Web Services method can only be used as The root object in the transaction. If the exception is caught from the web service method or is not captured by the method, the transaction is automatically abandoned. If no exception occurs, the transaction is automatically submitted unless the method explicitly calls setabort. Disable indication The XML Web Services method is not running within the range of transactions. When the request is handled, the XML Web Services method will be executed without transaction. [WebMethod (TransactionOption)] NotSupported indicates that the XML Web Services method is not running within the range of transactions. When the request is handled, the XML Web Services method will be executed without transaction. [WebMethod (TransactionOption = TransactionOption.Notsupported)] Supported (MSDN is wrong, here is correct) If there is a transaction, indicating that the XML Web Services method runs within the transaction. If there is no business, XML Web Services will be created without transactions. [WebMethod (TransactionOption = TransactionOption.supported) is required to indicate that the XML Web Services method requires transactions. Since the Web service method can only participate in the transaction as a root object, a new transaction will be created for the web service method. [WebMethod (TransactionOption)] RequiresNew indicates that the XML Web Services method requires a new transaction. When processing the request, XML Web Services will be created in a new transaction. [WebMethod (TransactionOption = TransactionOption.Requiresnew)] Here I have not practiced, so I can only copy MSDN, here, please include C # <% @ WebService language = "c #" class = "Bank"%> <% @ askEMBLY NAME = "System.EnterpriseServices"%> using System; using System.Web.Services; using System.EnterpriseServices; public class Bank: WebService {[WebMethod (TransactionOption = TransactionOption.RequiresNew)] public void Transfer (long Amount, long AcctNumberTo, long AcctNumberFrom ) {MyCOMObject objBank = new MyCOMObject (); if (objBank.GetBalance (AcctNumberFrom) 5) Cacheduration: Web supports the output cache so that WebService does not need to perform multiple times, which can improve access efficiency, and Cachedure is the properties of the specified cache time. C #: public static int i = 0; [weblease = true, cachedure = 30)] public int count () {i = i 1; return i;} Enter: In the address bar of IE: http://localhost/webservice1/service1.asmx/count? Refresh it, the same! To make the output, wait for 30 seconds. . . Because the code is executed again after 30 seconds, the result of the previously returned is the content in the server cache. 6) BUFFERRESPONSE Configuring whether the WebService method waits until the response is completely buffered, then send the information to the requested terminal. Ordinary application should be completely buffered to be sent! Take a look at the procedure below: C #: [WebMethod (BufferResponse = FALSE)] Public void HelloWorld1 () {INT i = 0; String S = ""; While (i <100) {s = s "i [WebMethod (BufferResponse = true)] public void helloworld2 () {INT i = 0; string s = ""; while (i <100) {s = s "i My example itself destroys the webservice return structure, so I took out the example in MSDN, don't blame! [C #]% @ Webservice Class = "streaming" Language = "C #"%> Using system; using system.collections; using system.xml.serialization; using system.Web.services; using system.web.services.protocols; Public class streaming { [WebMethod (BufferResponse = 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; Public textFileReaderwriter () {} Public textFileReaderWriter (String filename) {filename = filename; Public textfileEnumerator genumerator () {streamreader reader = new streamreader (filename); return new textfileEnumerator (Reader);} IEnumerator ienumerable.getenumerator () {return genumerator (); Public void add (String line) {if (writer == null) Writer = new streamwriter; 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;} else returse;} else return Public void reset () {reader.basestream.position = 0;} Public string current {get {return currentline;}} Object ienumerator.current {get {return current;}}} Author Blog: http://blog.9cbs.net/zfive5/
"; this.Context.Response.write s); i ;} return;
"; this.context.Response.write s); i ;} return;} From two methods executed in IE, you can see that they are different, the first, is pushing technology! What data is returned immediately, and the latter is to return the information to the requested end.