Silverlight开发实践--Get Data By WCF2010-05-10 博客园 GWPBrian实际的开发中,我们会经常的和数据库打交道。今天给大家带来的就是在silverlight中通过WCF同数据库进行交互。本人是菜鸟,高手见笑。

具体的代码我就不贴出来了,主要说说制作中遇到的困难和大家值得借鉴的东西。1)WCF的使用在添加WCF服务的时候,VS2008默认在Web.config中<endpoint address="" binding="wsHttpBinding "contract="ISLGetDataWCF">binding的值为wsHttpBinding,这里需要将其值改为basicHttpBinding,<endpoint address="" binding="basicHttpBinding"contract="ISLGetDataWCF">,否则在Silverlight调用WCF的时候生成的ServiceReferences.ClientConfig会出现错误。(2)Silverlight中页面的跳转普通的网站之间跳转页面很简单,但是在Sliverlight中,.xaml页面的跳转需要做点小工作(不知道有没有其他的方法,高手指教)这里的方法是在App.xaml中定义了一个跳转页面的函数
Canvas rootCanvas = new Canvas();
private void Application_Startup(object sender, StartupEventArgs e)
{
this.RootVisual = rootCanvas;
rootCanvas.Children.Add(new Page());
//this.RootVisual = new Page();
}
public void RedirectTo(UserControl usercontrol)
{
App app = (App)Application.Current;
app.rootCanvas.Children.Clear();
app.rootCanvas.Children.Add(usercontrol);
}
也可以定义一个Grid,就看你页面中的跟容器是什么了。也希望大家提供更好的方法。