这些场景(带有 Silverlight 的非 EntityFramework RIA 服务)肯定没有记录在案,我希望很快发布一些博客文章来涵盖这些场景(包括如何使用 NHibernate)。
这是执行您所要求的操作的一种方法:
如果尚未安装“Silverlight 4 Tools for Visual Studio 2010”,请安装:
在 Visual Studio 2010 中创建一个新的 Silverlight 导航应用程序(选中该框以启用 RIA 服务)。
修改web项目中的web.config,方法如下:
在 部分中,添加:
<httpModules>
<add name="DomainServiceModule"
type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule,
System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</httpModules>
添加 部分作为 的对等部分:
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
</system.serviceModel>
将以下引用添加到 Web 项目中:
System.ServiceModel.DomainServices.Hosting
System.ServiceModel.DomainServices.Server
在 Web 项目中创建一个新类 VanillaDomainService,其中包含“return 100”方法:
[System.ServiceModel.DomainServices.Hosting.EnableClientAccess()]
public class VanillaDomainService :
System.ServiceModel.DomainServices.Server.DomainService
{
public int ReturnInteger100()
{
return 100;
}
}
现在回到 Silverlight 应用程序项目,在 Home.xaml.cs 的 OnNavieratedTo 方法中,调用新的 RIA Services 方法(记住所有调用都是异步的):
protected override void OnNavigatedTo(NavigationEventArgs e)
{
SilverlightApplication1.Web.VanillaDomainContext oneVanillaDomainContext =
new SilverlightApplication1.Web.VanillaDomainContext();
oneVanillaDomainContext.ReturnInteger100(
anInt => MessageBox.Show(anInt.Value.ToString()), null);
}
现在构建并运行,应该就是这样了。
我测试了这段代码,它对我有用。