概要:

    基础知识终于学完了,我今天又从第一篇看到第十篇,发现明白了一些东西,还有忘记了部分东西。呵呵,咱不能猴子掰玉米,学了新的忘记旧的。
要经常去复习,去用。这一篇是数据通信部分的第一篇,有些东西没接触过,不要紧,万事开头难。前面也是这么走过来的么。。。

WebClient:

  webClient顾名思义,是用来上传或下载数据的服务。
  webClient提供的上传数据常用的有4种:
    OpenWrite   返回一个用于将数据发送到资源的  Stream。     
     UploadData   将字节数组发送到资源并返回包含任何响应的字节数组。     
      UploadFile   将本地文件发送到资源并返回包含任何响应的字节数组。     
      UploadValues   将   NameValueCollection   发送到资源并返回包含任何响应的字节数组。
  下载的有三种:
    DownloadData   从资源下载数据并返回字节数组。     
      DownloadFile   从资源将数据下载到本地文件。     
     OpenRead   从资源以   Stream   的形式返回数据。
  上面是从网上查来的,不一定对,但我认为已经可以解释清楚WebClient是干什么的了。
  这个例子是用client.DownloadStringAsync(地址);来下载数据的。

接口部分:

  using System.Web.Services;提供了
    [WebService(Namespace = "http://tempuri.org/")]//提供特性部分
       [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]//Web服务互操作性规范
  一般这些都不要管的,其实我也不太明白这些具体是跟什么的。
  此接口继承于IHttpHandler接口,我们要做的就是在声明接口后返回什么样的值。

代码:

  MainPage.xaml代码:
<UserControl x:Class="SilverlightAppDemo12.MainPage"
xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d
="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc
="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable
="d"
d:DesignHeight
="300" d:DesignWidth="400" Loaded="UserControl_Loaded">

<Grid Background="#46461F">
<Grid.RowDefinitions>
<RowDefinition Height="40"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="40"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<Border Grid.Row="0" Grid.Column="0" CornerRadius="15"
Width
="240" Height="36"
Margin
="20 0 0 0" HorizontalAlignment="Left">
<TextBlock Text="书籍列表" Foreground="White"
HorizontalAlignment
="Left" VerticalAlignment="Center"
Margin
="20 0 0 0"></TextBlock>
</Border>
<ListBox x:Name="Books" Grid.Row="1" Margin="40 10 10 10"
SelectionChanged
="Books_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Name}" Height="32"></TextBlock>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Border Grid.Row="2" Grid.Column="0" CornerRadius="15"
Width
="240" Height="36" Background="Orange"
Margin
="20 0 0 0" HorizontalAlignment="Left">
<TextBlock x:Name="lblPrice" Text="价格:" Foreground="White"
HorizontalAlignment
="Left" VerticalAlignment="Center"
Margin
="20 0 0 0"></TextBlock>
</Border>
</Grid>
</UserControl>

相关文章: