e股脑电脑教程网
  • 首 页
  • 操作系统
  • 应用软件
  • 下载工具
  • 影音视频
  • 办公软件
  • 媒体制作
  • 网站建设
  • 平面设计
  • 数据库
  • 程序开发
  • 视频教程
编辑推荐: | 文章搜索:
您现在的位置: e股脑 >> 程序开发 >> C教程 >> .Net下WebMethod属性 >> 教程正文
 
教程搜索
 
 
相关教程
  • 深入剖析C#继承机制
  • C#如何获得 WINDOWS 版本
  • C# 编码规范和编程好习惯
  • 获得汉字字符串拼音首字母 C#版
  • 利用C#实现标准的 Dispose模式
  • 在C#中应用哈希表(Hashtable)
  • 利用Delphi 2005 编写C#应用程序
  • 对C#泛型中的new()约束的一点思考
  • 身份证15To18 的算法(C#)
  • .Net下WebMethod属性
  • C#实现的18位身份证格式验证算法
  • C#中用API实现MP3等音频文件的播放类
  • 用C#把文件转换为XML
  • 如何得到硬盘序列号
  • Raw Socket编程实现网络封包监视
  • C#2.0 对AD的简单操作
 
 

图文教程


  • 将其他Email邮件转移到Gmail邮箱中

  • Vista破解TCP/IP后进不了系统咋办

  • Vista下用DriveSpacio查看磁盘空间

  • Windows抢了谁的饭碗 非主流操作系统To

  • 地球还是火星 平常心看“非主流”
 
 
赞 助 商
 
 
.Net下WebMethod属性
  • 来源:e股脑
  • 点击次数:
  • 更新时间:2007-8-9

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://tempuri.org/">19</int>

<?xml version="1.0" encoding="utf-8" ?>

<int xmlns="http://tempuri.org/">20</int>

......

......

通过它实现webservice数据库访问的事物处理,做过实验,可以哦!

3)MessageName:

主要实现方法重载后的重命名:

C#:

public static int i=0;

[WebMethod(EnableSession=true)]

public int Count()

{

i=i+1;

return i;

}

[WebMethod(EnableSession=true,MessageName="Count1")]

public int Count(int da)

{

i=i+da;

return i;

}

通过count访问的是第一个方法,而通过count1访问的是第二个方法!

4)TransactionOption:

指示 XML Web services 方法的事务支持。

这是msdn里的解释:

由于 HTTP 协议的无状态特性,XML Web services 方法只能作为根对象参与事务。

如果 COM 对象与 XML Web services 方法参与相同的事务,并且在组件服务管理工

具中被标记为在事务内运行,XML Web services 方法就可以调用这些 COM 对象。

如果一个 TransactionOption 属性为 Required 或 RequiresNew 的 XML Web services

方法调用 另一个 TransactionOption 属性为 Required 或 RequiresNew 的 XML Web services 方法,


每个 XML Web services 方法将参与它们自己的事务,因为XML Web services 方法只能用作事务中的

根对象。

如果异常是从 Web 服务方法引发的或未被该方法捕获,则自动放弃该事务。如果未发生异常,则自动提

交该事务,除非该方法显式调用 SetAbort。

禁用

指示 XML Web services 方法不在事务的范围内运行。当处理请求时,将在没有事务

的情况下执行 XML Web services 方法。

[WebMethod(TransactionOption= TransactionOption.Disabled)]

NotSupported

指示 XML Web services 方法不在事务的范围内运行。当处理请求时,将在没有事务的

情况下执行 XML Web services 方法。

[WebMethod(TransactionOption= TransactionOption.NotSupported)]

Supported (msdn里写错了,这里改正)

如果有事务,指示 XML Web services 方法在事务范围内运行。如果没有事务,将在没有事务的情况

下创建 XML Web services。

[WebMethod(TransactionOption= TransactionOption.Supported)]

必选

指示 XML Web services 方法需要事务。由于 Web 服务方法只能作为根对象参与事务,因

此将为 Web 服务方法创建一个新事务。

[WebMethod(TransactionOption= TransactionOption.Required)]

RequiresNew

指示 XML Web services 方法需要新事务。当处理请求时,将在新事务内创建 XML Web services。

[WebMethod(TransactionOption= TransactionOption.RequiresNew)]

这里我没有实践过,所以只能抄袭msdn,这里请包涵一下了

C#

<%@ WebService Language="C#" Class="Bank"%>

<%@ assembly name="System.EnterpriseServices" %>

using System;

using System.Web.Services;

using System.EnterpriseServices;

public class Bank : WebService {

[ WebMethod(Transact

1 2 3 下一页
  • 上一篇教程: C#实现的18位身份证格式验证算法
  • 下一篇教程: 身份证15To18 的算法(C#)
  •  

    关于本站 | 广告联系 | 版权声明 | 使用帮助

    Copyright © 2004-2008 www.egunao.com All rights reserved.