.net下WebMethod属性
来源:互联网 发布:无锡物联网 知乎 编辑:程序博客网 时间:2024/05/21 09:55
Author:zfive5(zhaozidong)
Email :zfive5@yahoo.com.cn
WebMethod有6个属性:
.Description
.EnableSession
.MessageName
.TransactionOption
.CacheDuration
.BufferResponse
1) Description:
是对webservice方法描述的信息。就像webservice方法的功能注释,可以让调用者看见
的注释。
C#:
[WebMethod(Description="Author:ZFive5 Function:Hello World") ]
public string HelloWorld()
{
return "Hello World";
}
WSDL:
- <portType name="Service1Soap">
- <operation name="HelloWorld">
<documentation>Author:ZFive5 Function:Hello World</documentation>
<input message="s0:HelloWorldSoapIn" />
<output message="s0:HelloWorldSoapOut" />
</operation>
</portType>
- <portType name="Service1HttpGet">
- <operation name="HelloWorld">
<documentation>Author:ZFive5 Function:Hello World</documentation>
<input message="s0:HelloWorldHttpGetIn" />
<output message="s0:HelloWorldHttpGetOut" />
</operation>
</portType>
- <portType name="Service1HttpPost">
- <operation name="HelloWorld">
<documentation>Author:ZFive5 Function:Hello World</documentation>
<input message="s0:HelloWorldHttpPostIn" />
<output message="s0:HelloWorldHttpPostOut" />
</operation>
</portType>
2)EnableSession:
指示webservice否启动session标志,主要通过cookie完成的,默认false。
C#:
public static int i=0;
[WebMethod(EnableSession=true)]
public int Count()
{
i=i+1;
return i;
}
在ie地址栏输入:
http://localhost/WebService1/Service1.asmx/Count?
点刷新看看
......
<?xml version="1.0" encoding="utf-8" ?>
<int xmlns="http://localhost/WebService1/Service1.asmx/Count?
刷新它,一样吧!要使输出不一样,等30秒。。。
因为代码30秒后才被再次执行,之前返回的结果都是在服务器高速缓存里的内容。
6)BufferResponse
配置WebService方法是否等到响应被完全缓冲完,才发送信息给请求端。普通应用要等完
全被缓冲完才被发送的!看看下面的程序:
C#:
[WebMethod(BufferResponse=false)]
public void HelloWorld1()
{
int i=0;
string s="";
while(i<100)
{
s=s+"i<br>";
this.Context.Response.Write(s);
i++;
}
return;
}
[WebMethod(BufferResponse=true)]
public void HelloWorld2()
{
int i=0;
string s="";
while(i<100)
{
s=s+"i<br>";
this.Context.Response.Write(s);
i++;
}
return;
}
从两个方法在ie里执行的结果就可以看出他们的不同,第一种,是推技术哦!
有什么数据马上返回,而后一种是把信息一起返回给请求端的。
我的例子本身破坏了webservice返回结构,所以又拿出msdn里的例子来,不要
怪哦!
[C#]
<%@WebService class="Streaming" language="C#"%>
using System;
using System.IO;
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 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;
}
}
}
转至:http://blog.csdn.net/zfive5/archive/2004/12/23/226811.aspx
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=226811
- .Net下WebMethod属性
- .Net下WebMethod属性
- .net下WebMethod属性
- .net 下webservice 的WebMethod的属性
- .NET 使用 WebMethod 属性
- 在ASP.NET WebService 中如何使用 WebMethod 属性
- WebMethod属性详解
- 使用 WebMethod 属性
- WebMethod属性详解
- [WebMethod]属性详解
- C# WebMethod中属性详解
- C# WebMethod中属性详解
- C# WebMethod中属性详解
- webservice中WebMethod的属性
- webservice 的WebMethod的属性
- webservice 中WebMethod属性详解
- WebService中webmethod的六个属性
- JQuery ajax调用asp.net的webMethod
- csdn与我
- 一个很好的模拟弹出窗口的特效 偶尔看到了收藏一下- -b
- java读取ApplicationResources.properties资源文件 (转贴)
- 发现使用phpAdmin更新数据的一个bug!
- 猫大叫一声,所有的老鼠都开始逃跑,主人被惊醒
- .net下WebMethod属性
- Visual C++开发工具与调试技巧整理
- 框架的高度随框架里面的内容的多少而改变
- BED 连接 Paradox
- PHP中单引号与双引号的区别
- Admin Added Access
- oledb(转载中程在线)
- VC++中使用低级音频函数WaveX播放声音文件
- 判断一个表是否存在