1:终端设备可以通过gprs,3g或者是wifi连接到网络当中。
2:写好服务器端程序,定以后服务器端需要终端调用来实现的函数。
3:建立一个智能设备应用程序,添加Web引用。
服务器代码:
private SqlConnection Conn;
private string ConnString = "Data Source=(local);Initial Catalog=Northwind;uid=sa;pwd=sa;";
dataConnection#region dataConnection
private DataSet GetNorthwindDataSet()
{
return ExecuteSql("select * from Employees");
}
private DataSet ExecuteSql(string mysql)
{
DataSet dataSet = new DataSet();
SqlDataAdapter adapter = new SqlDataAdapter(mysql, this.Conn);
try
{
if (this.Conn.State == ConnectionState.Closed)
{
this.Conn.Open();
}
adapter.Fill(dataSet, "table");
}
catch (Exception exception)
{
HttpContext.Current.Response.Write(exception.Message);
HttpContext.Current.Response.End();
}
finally
{
if ((this.Conn != null) && (this.Conn.State == ConnectionState.Open))
{
this.Conn.Close();
}
adapter.Dispose();
}
return dataSet;
}
#endregion
//方法一:直接返回 DataSet 对象
[WebMethod(Description = "直接返回 DataSet 对象。")]
public DataSet GetDataSet()
{
DataSet dataSet = GetNorthwindDataSet();
return dataSet;
}
终端代码:
private webSer.Service1 ws;
private void FrmMain_Load(object sender, EventArgs e)
{
ws = new DeviceApplication1.webSer.Service1();
}
//webmethod直接返回dataset
private void btnDataSet_Click(object sender, EventArgs e)
{
try
{
this.dtGrid.DataSource = null;
DateTime dtBegin = DateTime.Now;
DataSet ds = ws.GetDataSet();
DateTime dtDown = DateTime.Now;
this.dtGrid.DataSource = ds.Tables[0];
MessageBox.Show(string.Format("下载耗时:{0},绑定数据耗时:{1},数据量:{2}",
dtDown - dtBegin, DateTime.Now - dtDown, ds.GetXml().Length));
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}