Wp7可以方便得调用.net的WebService
先用C#做一个WebService,实现两个接口
GetMessage :发一条信息
SendMessage :接受最新一条信息
- using System;
- using System.Data;
- using System.Web;
- using System.Collections;
- using System.Web.Services;
- using System.Web.Services.Protocols;
- using System.ComponentModel;
- using System.Data.sqlClient;
- using COM;
- namespace WindowsService
- {
- /// <summary>
- /// Service1 の概要の説明です
- /// </summary>
- [WebService(Namespace = "http://tempuri.org/")]
- [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
- [ToolBoxItem(false)]
- public class Service1 : System.Web.Services.WebService
- {
- [WebMethod]
- public Message GetMessage(String id)
- {
- sqlConnection sqlCon = new sqlConnection();
- DataSet ds = new DataSet();
- Message msg = null;
- try
- {
- sqlCon = DBUtil.getsqlConnection();
- DBUtil.SelectsqlCommand(ds, "select TOP 1 body,sms_time from SMSTbl where id = '" + id + "' order by sms_time DESC", ref sqlCon);
- if (ds.Tables[0].Rows.Count > 0)
- {
- msg = new Message();
- msg.body = ds.Tables[0].Rows[0][0].ToString();
- msg.time = ds.Tables[0].Rows[0][1].ToString();
- }
- return msg;
- }
- finally
- DBUtil.closeConnection(sqlCon);
- }
- int SendMessage(String id, String body)
- return DBUtil.InsertsqlCommand("Insert into SMSTbl( id,sms_time,body) values('" + id + "',getdate(),'" + body + "')",248); line-height:18px"> }
- finally
- {
- DBUtil.closeConnection(sqlCon);
- }
- }
- }
再在wp7 程序引用WebService
在wp7里调用它
copy