1.在Web中添加天气服务引用地址

http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl

2.在Web中添加Wcf服务接口IWeatherService.cs

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.Serialization;
  5. using System.ServiceModel;
  6. using System.Text;
  7.  
  8. namespace EasySL.Web.WCF
  9. {
  10. // 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码和配置文件中的接口名“IWeatherService”。
  11. [ServiceContract]
  12. public interface IWeatherService
  13. {
  14. [OperationContract]
  15. string[] GetCityWeather(string CityName);
  16. }
  17. }

3.在Web中实现服务接口

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.Serialization;
  5. using System.ServiceModel;
  6. using System.Text;
  7.  
  8. namespace EasySL.Web.WCF
  9. {
  10. // 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码、svc 和配置文件中的类名“WeatherService”。
  11. // 注意: 为了启动 WCF 测试客户端以测试此服务,请在解决方案资源管理器中选择 WeatherService.svc 或 WeatherService.svc.cs,然后开始调试。
  12. public class WeatherService : IWeatherService
  13. {
  14. public string[] GetCityWeather(string CityName)
  15. {
  16. ServiceRefWeather.WeatherWebServiceSoapClient client = new ServiceRefWeather.WeatherWebServiceSoapClient("WeatherWebServiceSoap");
  17. string[] cityNameWeather = client.getWeatherbyCityName(CityName);
  18. return cityNameWeather;
  19. }
  20. }
  21. }

4.在client添加自己创建的Wcf服务地址、调用服务接口

  1. /// <summary>
  2. /// 通过wcf获取天气数据信息
  3. /// </summary>
  4. private void InitDataWeather()
  5. {
  6. try
  7. {
  8. ServiceReference1.WeatherServiceClient client = new ServiceReference1.WeatherServiceClient();
  9. client.GetCityWeatherCompleted += (s, e) =>
  10. {
  11. try
  12. {
  13. if (e.Error == null)
  14. {
  15. string[] cityWeather = new string[e.Result.Count];
  16. e.Result结果显示在页面中就ok了,然后我们将e.Result进行数据格式处理,运用独立存储讲结果保存起来 }
  17. else
  18. {
  19. lbltitle1.Content = e.Error.Message;
  20. }
  21. }
  22. catch (Exception ex)
  23. {
  24. lbltitle1.Content = ex.Message;
  25. }
  26.  
  27. };
  28. client.GetCityWeatherAsync("北京");
  29. }
  30. catch (Exception ex)
  31. {
  32. //lbltitle1.Content = ex.Message;
  33. }
  34.  
  35. }

5.将数据结果存放到本地(运用独立存储技术)

  1. private void WeatherWriterIsolatedStorageFile(string str)
  2. {
  3. IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
  4. if (isf.FileExists("Weather.txt"))
  5. {
  6. isf.DeleteFile("Weather.txt");
  7. }
  8. using (Stream stream = isf.CreateFile("Weather.txt"))
  9. {
  10. using (StreamWriter writer = new StreamWriter(stream))
  11. {
  12. writer.WriteLine(str);
  13. }
  14. }
  15. }

6.读取存放的数据结果(独立存储)

  1. private void ReaderWeatherIsolatedStorageFile()
  2. {
  3. IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
  4. if (isf.FileExists("AppConfig/Weather.txt"))
  5. {
  6. using (Stream stream = isf.OpenFile("Weather.txt", FileMode.Open))
  7. {
  8. using (StreamReader reader = new StreamReader(stream))
  9. {
  10. string[] line = reader.ReadToEnd().Split('|');
  11. }
  12. }
  13. isf.DeleteFile("Weather.txt");
  14. }
  15. else
  16. {
  17. InitDataWeather();
  18. }
  19. }

Silverlight 独立存储(IsolatedStorageFile)的更多相关文章

  1. Silverlight独立存储

    写 private void Button_Click_1(object sender, RoutedEventArgs e) { IsolatedStorageFile isf = Isolated ...

  2. 与众不同 windows phone (6) - Isolated Storage(独立存储)

    原文:与众不同 windows phone (6) - Isolated Storage(独立存储) [索引页][源码下载] 与众不同 windows phone (6) - Isolated Sto ...

  3. Silverlight-管理独立存储(Isolated Storage)

    Silverlight中的独立存储是其内部的可信任的可访问文件空间,在这里你可以使用Silverlight 随意的创建.读取.写入.删除目录和文件,它有一些类似于Cookie,但是它可以在客户端保存大 ...

  4. 【WP之一】]独立存储

    介绍: 提供一个磁盘存储空间,他是一种虚拟的文件系统,能存储小量的数据:在默认的情况下,它只能存储1MB的文件.根据使用方式及功能的不同,独立存储空间又包含两部分:独立设置存储和独立文件存储.除非卸载 ...

  5. WP_从独立存储区读取缓存的图片

      ///<summary> /// 独立存储缓存的图片源 /// 用法:item.img = new StorageCachedImage(newUri(http://www.baidu ...

  6. WP8 独立存储 总结3(应用设置)

    •可在独立存储中使用ApplicationSettings对象•在独立存储中存储键/值对的Dictionary方式存储 •存储的对象将永久保存 在应用设置中保存数据 void saveString(s ...

  7. Windows phone 之独立存储

    独立存储命名空间的说明:

  8. win10的独立存储

    win10的独立存储和win8的大致相同 Windows.Storage.ApplicationDataContainer roamingSettings = Windows.Storage.Appl ...

  9. Windows Phone 独立存储资源管理器工具

    如何使用独立存储资源管理器工具 http://msdn.microsoft.com/zh-CN/library/hh286408(v=vs.92)C:\Program Files (x86)\Micr ...

随机推荐

  1. Golang 图片上绘制文字

    之前介绍过使用 FreeType-go 来绘制字(http://www.cnblogs.com/ghj1976/p/3445568.html),  现在相关的包被做了整合,主要是整合到了 github ...

  2. Visual Studio 2015正式版/产品密钥 Win10正式版官方原版ISO镜像下载大全&安装激活教程

    Visual Studio 2015  发行说明: https://visualstudio.com/zh-cn/news/vs2015-vs.aspx Visual Studio  2015 特性简 ...

  3. POJ 2823【单调队列】

    题意: 给出序列,找出每个连续长度为k的子序列的最大值和最小值. 思路: 裸单调队列... 单调队列这东西用的真的非常局限,大概只能用到这种情景中== 简单说一下维护: 添加元素,为了保持单调性,排除 ...

  4. (easy)LeetCode 235.Lowest Common Ancestor of a Binary Search Tree

    Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BS ...

  5. Js字符串与十六进制的相互转换

    开发过程中,字符串与十六进.二进制之间的相互转换常常会用到,尤其是涉及到中文的加密时,就需要把中文转换为十六进制.下面说说具体的转换方法. 1.字符串转换为十六进制 主要使用 charCodeAt() ...

  6. [转]整理索引碎片,提升SQL Server速度

    数据库表A有十万条记录,查询速度本来还可以,但导入一千条数据后,问题出现了.当选择的数据在原十万条记录之间时,速度还是挺快的:但当选择的数据在这一千条数据之间时,速度变得奇慢. 凭经验,这是索引碎片问 ...

  7. 剑指Offer:面试题15——链表中倒数第k个结点(java实现)

    问题描述 输入一个链表,输出该链表中倒数第k个结点.(尾结点是倒数第一个) 结点定义如下: public class ListNode { int val; ListNode next = null; ...

  8. 你很牛B,面试却没过,为什么?

    点击标题下「飞测」可快速关注 坚持的是分享,搬运的是知识,图的是大家的进步,没有收费的培训,没有虚度的吹水,喜欢就关注.转发(免费帮助更多伙伴)等来交流,想了解的知识请留言,给你带来更多价值,是我们期 ...

  9. PMP考试--成本管理中常用的概念

    如果你对项目管理.系统架构有兴趣,请加微信订阅号"softjg",加入这个PM.架构师的大家庭 净现值(NPV)   Net Present Value 在项目计算期内,按行业基准 ...

  10. Microsoft Visual C++ 2010(86) Redistributable不能安装完美解决

    见http://jingyan.baidu.com/article/9c69d48f41aa6313c9024ebe.html 1. 去mircosoft下载安装包(vcredist_x64.exe) ...