1、Address类的代码:
1:
2: /// <summary>
3: /// Summary description for Address
4: /// </summary>
5: public class Address
6: {
7: public string Street;
8: public string City;
9: public int ZIP;
10: public string Country;
11:
12: public Address()
13: {
14: //
15: // TODO: Add constructor logic here
16: //
17: }
18: /// <summary>
19: /// Initializes a new instance of the Address class.
20: /// </summary>
21: /// <param name="_street"></param>
22: /// <param name="_city"></param>
23: /// <param name="_ZIP"></param>
24: /// <param name="_country"></param>
25: public Address(string _street, string _city, int _ZIP, string _country)
26: {
27: this.Street = _street;
28: this.City = _city;
29: this.ZIP = _ZIP;
30: this.Country = _country;
31: }
32: }
2、Web服务代码:
1: using System.Collections;
2: using System.Web.Services;
3: using System.Xml.Serialization;
4:
5:
6: /// <summary>
7: /// Summary description for CustomObjService
8: /// </summary>
9: [WebService(Namespace = "http://tempuri.org/")]
10: [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
11: // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
12: // [System.Web.Script.Services.ScriptService]
13: public class CustomObjectService : System.Web.Services.WebService {
14:
15: public CustomObjectService () {
16:
17: //Uncomment the following line if using designed components
18: //InitializeComponent();
19: }
20:
21: [WebMethodAttribute]
22: [XmlInclude(typeof(Address))]
23: public ArrayList GetArrayList()
24: {
25: ArrayList list = new ArrayList();
26: Address add1 = new Address("香山南路,20号", "北京", 100093, "中国");
27: Address add2 = new Address("玉泉路, 39号", "北京", 100092, "中国");
28: Address add3 = new Address("神仙路, 59", "贵阳", 30095, "中国");
29: Address add4 = new Address("Washiton Street, 30", "Washiton", 200056, "USA");
30: list.Add(add1);
31: list.Add(add2);
32: list.Add(add3);
33: list.Add(add4);
34: return list;
35: }
36:
37: }
38:
3、页面代码和输出结果
1: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
2:
3: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4:
5: <html xmlns="http://www.w3.org/1999/xhtml">
6: <head runat="server">
7: <title></title>
8: </head>
9: <body>
10: <form id="form1" runat="server">
11: <div>
12: <asp:GridView ID="grdAddress" runat="server"></asp:GridView>
13:
14: </div>
15: </form>
16: </body>
17: </html>