VS2013测试通过<作者:一剑>
1.新建“silverlight应用程序”项目;
2.右击web项目添加“新建项启用了Silverlight的WCF服务”;
3.修改
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 ws = new ServiceReference1.Service1Client(); ws.SayHelloCompleted += new EventHandler<ServiceReference1.SayHelloCompletedEventArgs>(SayHelloCompleted); ws.SayHelloAsync(textbox1.Text); } void SayHelloCompleted(object sender, ServiceReference1.SayHelloCompletedEventArgs e) { label1.Content = e.Result; }
8.Just run it!