想看一个大的案例,体会一下Webservice 到底牛B在何处?
Web service可以连接不同的应用平台.但要是把现有的各应用包装成Web service同样需要巨大的代价?
------解决方案--------------------
文件 study.asmx.cs
using system;
using system.collections;
using system.componentmodel;
using system.data;
using system.diagnostics;
using system.web;
using system.web.services;
using system.xml.serialization ;
namespace studyxml
{
/// <summary>
/// <br> 一个webservice的例子 </br>
/// <br> author:bigeagle@163.net </br>
/// <br> date: 2001/12/21 </br>
/// <br> history: 2001//12/21完成 </br>
/// </summary>
/// <remarks>
/// 这个webservice实现的功能很简单
/// 主要功能有两个,一个是取得预定义的item数组
/// 另一个是保存record类型的纪录
/// </remarks>
public class study : system.web.services.webservice
{
private arraylist m_arritems ;
private arraylist m_arrreocrds ;
public study()
{
//codegen: this call is required by the asp.net web services designer
initializecomponent();
this.m_arrreocrds = new arraylist() ;
this.m_arritems = new arraylist() ;
//增加一些实验数据
for(int i = 0 ; i < 100 ; i ++)
{
this.m_arritems.add(new item( "itemname " + i.tostring()
, "itemvalue " + (i + 1).tostring())) ;
}
}
/// <summary>
///
/// </summary>
/// <param name= "a_stritemname "> item name </param>
/// <returns> item对象 </returns>
private item getitem(string a_stritemname)
{
//throw(new exception(server.urldecode(a_stritemname))) ;
for(int i = 0 ; i < this.m_arritems.count ; i ++)
{
item item = (item)this.m_arritems[i] ;
if(item.name == server.urldecode(a_stritemname).trim())
{
return item ;
}
}
return null ;
}
#region component designer generated code
//required by the web services designer
private icontainer components = null;
/// <summary>
/// required method for designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void initializecomponent()
{
}
/// <summary>
/// clean up any resources being used.
/// </summary>
protected override void dispose( bool disposing )
{
if(disposing && components != null)
{
components.dispose();
}
base.dispose(disposing);
}
#endregion
[webmethod]
public void additem(string a_strname , string a_strvalue)
{
this.m_arritems.add(new item(a_strname , a_strvalue));
}
/// <summary>
/// 取得item列表
/// </summary>