@H_404_4@
作为一个Silverlight新手,我发现很难建立一个RIA Web服务. Web上可用的示例几乎总是将实体框架称为ORM,但我们使用NHibernate作为我们的ORM.我知道Brad Abrams的教程,他使用NHibernate作为ORM,但大多数都是我的头脑,因为我也是NHibernate的新手,RIA的一些概念对我来说并不清楚,例如的DomainService.
我想首先保持简单,暂时忽略ORM.那么,任何人都可以指出我正确的方向,如何使用Silverlight 4.0和最新版本的RIA获得“vanilla”Web服务?例如,我如何公开一个返回整数100然后从我的SilverLight应用程序调用该方法的方法?此外,我不确定它是否相关,但Silverlight应用程序是在ASP.NET MVC 2中托管的.
对我而言,它应该是如此简单,但我现在真的很挣扎.
TIA,
大卫
解决方法
这些场景(使用Silverlight的非EntityFramework RIA服务)肯定已记录在案,我希望尽快发布一些博客文章来涵盖这些场景(包括如何使用NHibernate).
这是一种做你要求的方法:
如果您还没有安装“适用于Visual Studio 2010的Silverlight 4工具”:
在Visual Studio 2010中创建新的Silverlight导航应用程序(选中此框以启用RIA服务).
<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>作为< system.web>的对等部分:
<system.serviceModel> <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> </system.serviceModel>
将以下引用添加到Web项目:
System.ServiceModel.domainservices.Hosting System.ServiceModel.domainservices.Server
在包含“return 100”方法的Web项目中创建一个新类VanillaDomainService:
[System.ServiceModel.domainservices.Hosting.EnableClientAccess()] public class VanillaDomainService : System.ServiceModel.domainservices.Server.DomainService { public int ReturnInteger100() { return 100; } }
现在回到Silverlight应用程序项目,在Home.xaml.cs中,在OnNavigatedTo方法中,调用新的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); }
现在构建并运行,应该是它.