WEB开发网
开发学院图形图像Flash 学Silverlight 2系列(33):Silverlight 2应用We... 阅读

学Silverlight 2系列(33):Silverlight 2应用Web Service两例

 2008-10-09 11:39:51 来源:WEB开发网   
核心提示: <Grid x:Name="LayoutRoot" Background="#333333"><Grid.RowDefinitions><RowDefinition Height="70">&l

<Grid x:Name="LayoutRoot" Background="#333333">
  <Grid.RowDefinitions>
    <RowDefinition Height="70"></RowDefinition>
    <RowDefinition Height="50"></RowDefinition>
    <RowDefinition Height="50"></RowDefinition>
    <RowDefinition Height="200"></RowDefinition>
    <RowDefinition Height="50"></RowDefinition>
  </Grid.RowDefinitions>
  <Grid.ColumnDefinitions>
    <ColumnDefinition Width="100"></ColumnDefinition>
    <ColumnDefinition Width="*"></ColumnDefinition>
  </Grid.ColumnDefinitions>
  <local:TitleControl Grid.Row="0" Margin="8,8,8,8" Grid.ColumnSpan="2"></local:TitleControl>
  <TextBlock Text="收件人" Grid.Row="1" Style="{StaticResource textBlockStyle}"></TextBlock>
  <TextBlock Text="主 题" Grid.Row="2" Style="{StaticResource textBlockStyle}"></TextBlock>
  <TextBox x:Name="txtToEmailAddress" Grid.Row="1" Grid.Column="1" Width="440" Height="30" HorizontalAlignment="Left"></TextBox>
  <TextBox x:Name="txtSubject" Grid.Row="2" Grid.Column="1" Width="440" Height="30" HorizontalAlignment="Left"></TextBox>
  <TextBox x:Name="txtBody" Grid.Row="3" Grid.ColumnSpan="2" Width="500" HorizontalAlignment="Left" Height="200" Margin="100 0 0 0"></TextBox>
  <Button x:Name="btnSend" Grid.Row="4" Grid.Column="1" HorizontalAlignment="Left" Content="发 送"
      Style="{StaticResource buttonStyle}" Width="120" Height="30"
      Click="OnSendClick"></Button>
 </Grid>

在Silverlight项目中添加Web Service引用,并编写代码来调用Web Service,相信大家都已经熟悉了该如何调用,如下代码所示:

void OnSendClick(object sender, RoutedEventArgs e)
{
  // 发送邮件地址
  String fromAddress = "terrylee1218@gmail.com";
  EmailServiceSoapClient client = new EmailServiceSoapClient();
  client.SendCompleted += new EventHandler<SendCompletedEventArgs>(OnSendCompleted);
  client.SendAsync(fromAddress,
           this.txtToEmailAddress.Text,
           this.txtSubject.Text,
           this.txtBody.Text);
}
void OnSendCompleted(object sender, SendCompletedEventArgs e)
{
  if (e.Result)
  {
    HtmlPage.Window.Alert("发送邮件成功!");
  }
  else
  {
    HtmlPage.Window.Alert("发送邮件成功!");
  }
}
运行后输入相关信息,并发送邮件,如下图所示:

学Silverlight 2系列(33):Silverlight 2应用Web Service两例

至此我们就完成一个在Silverlight中发送电子邮件的示例,大家如果有兴趣,还可以为其加上更加丰富的功能,如添加抄送人、密送人以及附件等。

上一页  1 2 3 4 

Tags:Silverlight 系列 Silverlight

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接