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

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

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

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text; namespace EasySL.Web.WCF
{
// 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码和配置文件中的接口名“IWeatherService”。
[ServiceContract]
public interface IWeatherService
{
[OperationContract]
string[] GetCityWeather(string CityName);
}
}

3.在Web中实现服务接口

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

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

/// <summary>
/// 通过wcf获取天气数据信息
/// </summary>
private void InitDataWeather()
{
try
{
ServiceReference1.WeatherServiceClient client = new ServiceReference1.WeatherServiceClient();
client.GetCityWeatherCompleted += (s, e) =>
{
try
{
if (e.Error == null)
{
string[] cityWeather = new string[e.Result.Count];
讲e.Result结果显示在页面中就ok了,然后我们将e.Result进行数据格式处理,运用独立存储讲结果保存起来 }
else
{
lbltitle1.Content = e.Error.Message;
}
}
catch (Exception ex)
{
lbltitle1.Content = ex.Message;
} };
client.GetCityWeatherAsync("北京");
}
catch (Exception ex)
{
//lbltitle1.Content = ex.Message;
} }

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

  private void WeatherWriterIsolatedStorageFile(string str)
{
IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
if (isf.FileExists("Weather.txt"))
{
isf.DeleteFile("Weather.txt");
}
using (Stream stream = isf.CreateFile("Weather.txt"))
{
using (StreamWriter writer = new StreamWriter(stream))
{
writer.WriteLine(str);
}
}
}

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

 private void ReaderWeatherIsolatedStorageFile()
{
IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
if (isf.FileExists("AppConfig/Weather.txt"))
{
using (Stream stream = isf.OpenFile("Weather.txt", FileMode.Open))
{
using (StreamReader reader = new StreamReader(stream))
{
string[] line = reader.ReadToEnd().Split('|');
}
}
isf.DeleteFile("Weather.txt");
}
else
{
InitDataWeather();
}
}

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. Java内存区域分配基恩内存溢出异常

  2. How to make 9-patch image downloaded from the Network

    Probably everyone, who is in touch with the Android world dealt with 9-patch term. It is an image in ...

  3. kylin一种OLAP的实现

    1.基于hive.hadoop的预先计算. 2.cube存储在HBASE里面.利用HBase的列存储,实现MOLAP 3.在cube上做数据分析,kylin实现标准的SQL,实现查询HBase 所以说 ...

  4. php文件删除unlink()详解

    请记住从PHP文件创建的教训,我们创建了一个文件,名为testFile.txt . $myFile = "testFile.txt"; $fh = fopen($myFile, ' ...

  5. Integer cache

    View.findViewById采用深度遍历,找到第一个匹配的控件 Integer Cache public static void testIntegerCache() { Class cache ...

  6. Codeforces Round #218 (Div. 2) C. Hamburgers

    C. Hamburgers time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  7. [ CodeVS冲杯之路 ] P1053

    不充钱,你怎么AC? 题目:http://codevs.cn/problem/1053/ 直接扫一遍串,把字母对应的 ascii 码直接做数组下标,交给数组统计 最后查询一遍数组的 'a'-'z' , ...

  8. Yii 中比较常用的rules验证规则记录

    查看代码   打印 01 return array( 02   03     //必须填写 04     array('email, username, password,agree,verifyPa ...

  9. WebView 获取网页点击事件

    网页上的点击按钮 本身绑定了URL,点击的时候webview 会在下面的这个方法中加载URL - (BOOL)webView:(UIWebView*)webView shouldStartLoadWi ...

  10. Android开发如何去除标题栏title

    虽然是一个小问题,今天遇到了,也就写下来吧.防止自己忘掉. 取消标题栏的方式有两种,一种是在代码添加,另一种是在AndroidManifest.xml里面添加. 1.在代码中实现:在此方法setCon ...