加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Wp7 调用WebService

发布时间:2020-12-17 01:03:58 所属栏目:安全 来源:网络整理
导读:Wp7可以方便得调用.net的WebService ? 先用C#做一个WebService,实现两个接口 GetMessage ?:发一条信息 SendMessage ?:接受最新一条信息 [c-sharp] ? view plain copy using ?System;?? using ?System.Data;?? using ?System.Web;?? using ?System.Collect

Wp7可以方便得调用.net的WebService

?

先用C#做一个WebService,实现两个接口

GetMessage?:发一条信息

SendMessage?:接受最新一条信息

[c-sharp]? view plain copy
  1. using?System;??
  2. using?System.Data;??
  3. using?System.Web;??
  4. using?System.Collections;??
  5. using?System.Web.Services;??
  6. using?System.Web.Services.Protocols;??
  7. using?System.ComponentModel;??
  8. using?System.Data.SqlClient;??
  9. using?COM;??
  10. ??
  11. namespace?WindowsService??
  12. {??
  13. ????///?<summary>??
  14. ????///?Service1?の概要の説明です??
  15. ///?</summary>??
  16. ????[WebService(Namespace?=?"http://tempuri.org/")]??
  17. ????[WebServiceBinding(ConformsTo?=?WsiProfiles.BasicProfile1_1)]??
  18. ????[ToolboxItem(false)]??
  19. ????public?class?Service1?:?System.Web.Services.WebService??
  20. ????{??
  21. ??
  22. ????????[WebMethod]??
  23. ????????public?Message?GetMessage(String?id)??
  24. ????????{??
  25. ????????????SqlConnection?SqlCon?=?new?SqlConnection();??
  26. ????????????DataSet?ds?=?new?DataSet();??
  27. ????????????Message?msg?=?null;??
  28. ????????????try??
  29. ????????????{??
  30. ????????????????SqlCon?=?DBUtil.getSqlConnection();??
  31. ????????????????DBUtil.SelectSqlCommand(ds,?"select?TOP?1?body,sms_time?from?SMSTbl?where?id?=?'"?+?id?+?"'?order?by?sms_time?DESC",?ref?SqlCon);??
  32. ????????????????if?(ds.Tables[0].Rows.Count?>?0)??
  33. ????????????????{??
  34. ????????????????????msg?=?new?Message();??
  35. ????????????????????msg.body?=?ds.Tables[0].Rows[0][0].ToString();??
  36. ????????????????????msg.time?=?ds.Tables[0].Rows[0][1].ToString();??
  37. ????????????????}??
  38. return?msg;??
  39. ????????????}??
  40. finally??
  41. ????????????????DBUtil.closeConnection(SqlCon);??
  42. ????????}??
  43. int?SendMessage(String?id,?String?body)??
  44. ????????????????return?DBUtil.InsertSqlCommand("Insert?into?SMSTbl(?id,sms_time,body)?values('"?+?id?+?"',getdate(),'"?+?body?+?"')",248); line-height:18px"> ????????????}??
  45. ????????????finally??
  46. ????????????{??
  47. ????????????????DBUtil.closeConnection(SqlCon);??
  48. ????????}??
  49. ????}??
  50. }??

再在wp7 程序引用WebService

在wp7里调用它

copy

    //添加引用??
  1. using?DecoMailer.ServiceReference1;??
  2. //在[按钮]押下事件中?????????
  3. ?private?void?KanjiModeButton_Click(object?sender,?RoutedEventArgs?e)??
  4. //实例化SoapClient??
  5. ????????????ServiceReference1.Service1SoapClient?soap?=?new?Service1SoapClient();??
  6. //调用GetMessage方法,并把ID:1传给方法??
  7. ????????????soap.GetMessageAsync("1");??
  8. //Respones将触发GetMessageCompletedEvent事件,并调用soap_GetMessage处理??
  9. ????????????soap.GetMessageCompleted?+=?new?EventHandler<GetMessageCompletedEventArgs>(soap_GetMessage);??
  10. void?soap_GetMessage(if?(e.Error?==?null)??
  11. //取得最新的Message类对象??
  12. ????????????????ServiceReference1.Message?lastMessage?=?e.Result;??
  13. ????????????????//MessageEditor.Message?=?lastMessage;??
  14. ????????}??

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读