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. [ActionScript 3.0] AS3实现图像径向转旋效果

    原图    效果     import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.Blen ...

  2. VisualVM 的 OQL 的一些例子

    Visual VM的OQL语言是对HeapDump进行查询,类似于SQL的查询语言,它的基本语法如下: select <JavaScript expression to select> [ ...

  3. windows查看端口占用

    查看占用端口的进程ID netstat -aon | findstr "9000" 再用进程ID查看进程 tasklist | findstr "6048"

  4. nyoj 56-阶乘因式分解(一)

    点击打开链接 阶乘因式分解(一) 时间限制:3000 ms  |  内存限制:65535 KB 难度:2 描述 给定两个数m,n,其中m是一个素数. 将n(0<=n<=10000)的阶乘分 ...

  5. JBPM的引擎内核学习

    http://atongyeye.iteye.com/blog/2093505 流程引擎 http://www.cnblogs.com/aspnetx/archive/2009/09/24/15735 ...

  6. 网站注册(css)

    <! DOCTYPE HTML><html><head><meta charset="utf-8"><title>作业2 ...

  7. unity3d学习重点记录

    本文主要是记录在学习unity3d中遇到的重点功能的实现,以及一些API的使用方法.以便在以后使用到的时候查找. 1,给一个UIButton添加执行的事件 // Use this for initia ...

  8. Flex对象的Clone & Copy浅析

    在flex中有时候会用到ObjectUtil.clone和ObjectUtil.copy方法.下面是官方API的注释. 克隆指定对象,并返回对该克隆的引用.该克隆使用本机序列化技术生成.这意味着在克隆 ...

  9. IIS装好了无法访问localhost

    解决办法:                 [1]:                 检查你的DTC服务(全名:Distributed Transaction Coordinator)是否可以正常启动 ...

  10. C和C++混合编译

    关于extern_C 通常,在C语言的头文件中经常可以看到类似下面这种形式的代码: #ifdef __cplusplus extern "C" { #endif /**** som ...