您的位置:知识库 » .NET技术

创建一个示例和WebMethod特性解析

作者: VisualStudio  来源: 博客园  发布时间: 2008-10-14 23:38  阅读: 12683 次  推荐: 1   原文链接   [收藏]  

系列文章导航:

创建一个示例和WebMethod特性解析

WebService特性和数组类型解析

类和结构体解析

利用YAHOO公开API做天气预报Web服务

Webservice 的设计和模式

Remoting和Webservice的区别


 

WebMethod特性的MessageName属性

Web服务禁止使用函数重载。MessageName属性可以解决由多个相同的名称的方法造成的无法识别的问题,它允许对每一个方法的重载使用唯一的别名。当从在方法在SOAP消息中引用时,SOAP将使用MessageName而非方法名。

在上面的例子中,为了试验这个属性,我改了一下,写两个GetCollege()方法。

 

       [WebMethod(Description = "根据学号获得学生的学院", MessageName = "GetCollegeStuNum")]
        
public string GetCollege(string strStuNum)
        {
            
for (int i = 0; i < strStuInfo.GetLength(0); i++)
            {
                
if (String.Compare(strStuNum, strStuInfo[i, 0], true== 0)
                {
                    
return strStuInfo[i, 2].ToString();
                }
            }
            
return "您输入的学号不存在";
        }

        [WebMethod(Description 
= "根据排名获得学生的学院", MessageName = "GetCollegeStuRank")]
        
public string GetCollege(int intStuRank)
        {
            
for (int i = 0; i < strStuInfo.GetLength(0); i++)
            {
                
if (String.Compare(intStuRank.ToString(), strStuInfo[i, 6], true== 0)
                {
                    
return strStuInfo[i, 2].ToString();
                }
            }
            
return "您输入的学生排名不存在";
        }

 

 

1
0
 

.NET技术热门文章

    .NET技术最新文章

      最新新闻

        热门新闻