silverlight+WCF之Hello world
VS2013测试通过<作者:一剑>
1.新建“silverlight应用程序”项目;
2.右击web项目添加“新建项启用了Silverlight的WCF服务”;
3.修改
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
public void DoWork() { return; }
为
public string SayHello(string userName) { return userName + ",hello world!!"; }
4.生成一下;
5.右击客户端项目,添加“服务引用”,发现-》确认;
6.MainPage.xaml,添加一个textbox、一个button和一个label控件;
7.修改MainPage.xaml.cs,增加
private void button1_Click(object sender, RoutedEventArgs e) {
ServiceReference1.Service1Client myClient = new ServiceReference1.Service1Client();
myClient.SayHelloCompleted += mySayHelloCompleted;
myClient.SayHelloAsync(textbox1.Text);
}
void mySayHelloCompleted(object sender, ServiceReference1.SayHelloCompletedEventArgs e) { label1.Content = e.Result; }
8.Just run it!