1. Build the model layer first:
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Namespace Air.model
{
public class city
{
private int _cityid;
public int Cityid
{
get {return _cityid;}
set {_cityid = value;}
}
private string _cityname;
public string CityName
{
get {return _cityname;}
set {_cityname = value;}
}
private string _districtcode;
public string Districtcode
{
get {return _districtcode;}
set {_districtcode = value;}
}
}
}
2.. Webservice Reflection method
Using System;
Using System.Data;
Using System.Linq;
Using System.Web;
Using System.Collections;
Using System.Web.Services;
Using System.Xml;
Using System.Xml.Schema;
Using System.Xml.Serialization;
Using System.Collections.Generic;
Using Air.model;
Namespace Air.airservice
{
[WebService (Namespace = "http://tempuri.org/")]
[WebServiceBinding (ConformsTo = wsiprofiles.basicprofile1_1)]
[ToolboxItem (False)]
public class AirService:System.Web.Services.WebService
{
[WebMethod]
Public list<city> Getcitys ()
{
List<city> citys = new list<city> ();
return citys;
}
}
3. Referencing Web Services
Select Web Services in this solution if used for the same project
If the local call is selected, Web services on the machine
If the remote call hangs in the browse UDDI Servers on the local network
Select the Web service you want
Change the Web resource name and click Add Web Reference
4. Calling Web Methods
public void DataBind () {
Airservice.airservice airservice = new Air.AirService.AirService ();
list<city> DataSource = Airservice.getcitys ();
}
As a method of returning a generic collection for WebService, it should be noted that WebService can only return a type and not return an interface, and an object error cannot be serialized if ilist<t> is used.