学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"></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中发送电子邮件的示例,大家如果有兴趣,还可以为其加上更加丰富的功能,如添加抄送人、密送人以及附件等。
Tags:Silverlight 系列 Silverlight
编辑录入:爽爽 [复制链接] [打 印]- ››silverlight全屏显示图片
- ››Silverlight MVVM 模式(一) 切近实战
- ››Silverlight for Windows Phone 7开发系列(1):...
- ››Silverlight for Windows Phone 7开发系列(2):...
- ››Silverlight for Windows Phone 7开发系列(3):...
- ››Silverlight for Windows Phone 7开发系列(4):...
- ››Silverlight for Symbian
- ››Silverlight3系列(四)数据绑定 Data Binding 1
- ››silverlight2 游戏 1 你能坚持多少秒
- ››Silverlight开发实践--PicZoomShow
- ››Silverlight自定义控件开发 - 令人懊恼的OnApplyT...
- ››Silverlight 2 RTW中ToolTipService.ToolTip不继承...
更多精彩
赞助商链接