RIA Services之商业应用----7 使用RIA Service Class Library

我今天看那个帖子的回帖有人说网上现在根本找不到一个完整的例子使用RIA Service Class Library这个模板的例子。我这里就还是使用AdvancedWorks给大家提供个例子。
1.       首先是创建一个普通的Silverlight Application项目,你也可以使用Business Application模板。
不勾选使用RIA Service,如下图:
2.       然后添加一个RIA Service Class Library模板。
  
3.       创建好以后的结构如下图:
 
4.       接下来是需要给Sample例子添加Reference
 
RIAServiceClassLibrarySample.Web添加ReferenceAdventureWorksClassLibrary.Web这个Project
同样的方法给RIAServiceClassLibrarySample添加AdventureWorksClassLibrary这个Reference
5.       下面这一步就是就不多说了,创建Domain Service,最后AdventureWorksClassLibrary.Web结构如下:
 
6.       Domain Service完成后我们需要给RIAServiceClassLibrarySample添加一个dll:
 
现在我们就可以在RIAServiceClassLibrarySample中使用RIA Service了。
我就直接给出在mainPage中的代码吧:
XAmL
<UserControl x:Class="RIAServiceClassLibrarySample.MainPage"
   xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="600" d:DesignWidth="800">
 
    <Grid x:Name="LayoutRoot" Background="White">
        <data:DataGrid Name="EmployeesGrid"></data:DataGrid>
    </Grid>
</UserControl>
 
后台.cs文件代码:
   private EmployeeDomainContext _employeeContext = new EmployeeDomainContext();
        public MainPage()
        {
            InitializeComponent();
            LoadOperation<Employee> loadOe= this._employeeContext.Load(this._employeeContext.GetEmployeesQuery());
            EmployeesGrid.ItemsSource = loadOe.Entities;
        }
 
7.       最后一步是把在AdventureWorksClassLibrary.Web项目中生成的app.config文件内容拷贝到RIAServiceClassLibrarySample.Web项目中的web.config中。
8.     <?xml version="1.0"?>
9.      
10.  <!--
11.    For more information on how to configure your ASP.NET application, please visit
12.    http://go.microsoft.com/fwlink/?LinkId=169433
13.    -->
14.   
15.  <configuration>
16.      <system.web>
17.          <compilation debug="true" targetFramework="4.0" />
18.          <httpModules>
19.              <add name="DomainServiceModule" type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
20.          </httpModules>
21.      </system.web>
22.      <system.serviceModel>
23.          <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
24.            multipleSiteBindingsEnabled="true" />
25.      </system.serviceModel>
26.      <connectionStrings>
27.          <add name="ADVENTUREWORKSEntities" connectionString="metadata=res://*/EmployeeModel.csdl|res://*/EmployeeModel.ssdl|res://*/EmployeeModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=WSBEI510019;Initial Catalog=ADVENTUREWORKS;Persist Security Info=True;User ID=sa;Password=Ist12345;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />
28.      </connectionStrings>
29.      <system.webServer>
30.          <modules runAllManagedModulesForAllRequests="true">
31.              <add name="DomainServiceModule" preCondition="managedHandler"
32.                type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
33.          </modules>
34.          <validation validateIntegratedModeConfiguration="false" />
35.      </system.webServer>
36.  </configuration>
37.   
 
38.   运行一下看看结果:
 
不错。。。。
总结一下: 使用RIA Service Class Library时需要注意:
a.     Reference的添加。
b.     添加System.ServiceModel.DomainServices.Client.dll这个Assembly
c.      Web.config文件的修改。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值