Silverlight 独立存储(IsolatedStorageFile)
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)的更多相关文章
- Silverlight独立存储
写 private void Button_Click_1(object sender, RoutedEventArgs e) { IsolatedStorageFile isf = Isolated ...
- 与众不同 windows phone (6) - Isolated Storage(独立存储)
原文:与众不同 windows phone (6) - Isolated Storage(独立存储) [索引页][源码下载] 与众不同 windows phone (6) - Isolated Sto ...
- Silverlight-管理独立存储(Isolated Storage)
Silverlight中的独立存储是其内部的可信任的可访问文件空间,在这里你可以使用Silverlight 随意的创建.读取.写入.删除目录和文件,它有一些类似于Cookie,但是它可以在客户端保存大 ...
- 【WP之一】]独立存储
介绍: 提供一个磁盘存储空间,他是一种虚拟的文件系统,能存储小量的数据:在默认的情况下,它只能存储1MB的文件.根据使用方式及功能的不同,独立存储空间又包含两部分:独立设置存储和独立文件存储.除非卸载 ...
- WP_从独立存储区读取缓存的图片
///<summary> /// 独立存储缓存的图片源 /// 用法:item.img = new StorageCachedImage(newUri(http://www.baidu ...
- WP8 独立存储 总结3(应用设置)
•可在独立存储中使用ApplicationSettings对象•在独立存储中存储键/值对的Dictionary方式存储 •存储的对象将永久保存 在应用设置中保存数据 void saveString(s ...
- Windows phone 之独立存储
独立存储命名空间的说明:
- win10的独立存储
win10的独立存储和win8的大致相同 Windows.Storage.ApplicationDataContainer roamingSettings = Windows.Storage.Appl ...
- Windows Phone 独立存储资源管理器工具
如何使用独立存储资源管理器工具 http://msdn.microsoft.com/zh-CN/library/hh286408(v=vs.92)C:\Program Files (x86)\Micr ...
随机推荐
- 微信红包签名算法 C#代码实现
string stringA = "appid=wxd930ea5d5a258f4f&body=test&device_info=1000&mch_id=100001 ...
- Words in Coding Theory
Lemma d(x.y) wt(c,0) self-dual self-orthogonal even prime wt(C) matrix column permute permutation ge ...
- IOS学习之路-- 指针&宏函数
如果*p被()包住,说明指针变量p将来指向的是函数 //声明一个指针变量 //int (*p)(int, int) = sum; int (*p)(int, int); p = sum; // 如果* ...
- Android Screen Monitor抓取真机屏幕
今天看到一款有点意思的开源软件“android-screen-monitor”, 简要记录如下: 1 简介 一款同步手机真机屏幕到PC上的软件(屏幕实时抓取,有点小卡) 2 开源地址 http://c ...
- docker错误
错误:cannot enable tty mode on non tty input 错误产生: root@machine1:/data# echo test|docker exec -i 68 ...
- 日志挖掘Logmnr
日志挖掘 9.1 日志中数据用途 所有对用户数据以及数据字典的改变全部被保存在联机日志中.当然nologging,insert/*+append+/情况比较特殊除外,因此归档日志可以用来做数据库的恢复 ...
- winform异步进度条LongTime
winform异步进度条LongTime,运用到回调函数 定义事件的参数类: namespace LongTime.Business { // 定义事件的参数类 public class ValueE ...
- 你不知道的JavaScript 二
词法作用域 上次说到作用域,将其定义为一套规则,这套规则用来管理引擎如何在当前作用 域以及嵌套的子作用域中根据标识符名称进行变量查找. 作用域共有两种主要的工作模型.第一种是最为普遍的,被大多数编程语 ...
- 创建一个提供数据 API 的 Node.js 网站
创建站点目录 首先,创建一个文件夹用来保存你的站点文件,使用 mkdir 就可以了 PS C:\> mkdir mysite 然后,进入到这个文件夹进行下一步的操作. 创建包说明 使用记事本或者 ...
- Oracle中MD5+Base64加密实现
JAVA实现: public static String getMD5(String str) throws Exception { MessageDigest md5 = MessageDige ...