
Domain Services 是向客户端公开数据访问层的WCF Services。当我们创建一个domain services实例时,就指定了想要公开的实体类,以及这个domain Services所允许的数据 *** 作。
DomainService类 和派生类
DomainService类是所有做为domain Services的服务类的基类。WCF RIA Services还提供了linqToEntitIEsDomainService(TContext)和linqTosqlDomainService(TContext)类,这两个类是从DomainService类派生出来的抽象类。
如果想创建绑定一个ADO.NET实体模型或一个liNQ to sql类,我们需要分别创建从linqToEntitIEsDomainService(TContext)或linqTosqlDomainService(TContext)派生的类。如果创建绑定到自定义数据对象的domain Service,就需要创建一个从DomainService类派生的类。当我们使用Add New Domain Service Class对话框来创建domain service时,会根据想要公开的实体自动创建正确的domain service类型。
一个domain service必须标记EnableClIEntAccessAttribute属性,才能被客户端项目引用。
通过在domain service中添加方法来执行我们想公开的数据 *** 作。例如,可以添加方法来执行以下 *** 作:
还可以添加更复杂的 *** 作,如下:
处理 *** 作 Resolve - 在服务端通过代码来处理发生的冲突。 调用 *** 作 Invoke - 那些不用追踪或延期运行的 *** 作。 命名的更新 *** 作 named Update - 不是简单修改的自定义 *** 作。命名约定
当我们添加方法来执行这些 *** 作时,这些方法必须满足这些 *** 作需要的签名。除了满足签名外,方法还应包含一个满足这个 *** 作命名约定的名字前缀。如果方法的名字不是由预期的名字前缀开始的,就必须对这个 *** 作应用一致的属性。如果 *** 作的名字满足命名约定,那么属性就是可选的。
我们不能重载那些是域 *** 作的方法。我们必须对每一个可以从客户端调用的方法指定唯一的名字。所有表示domain service *** 作的方法都应该是public的。方法对参数和返回值应使用串行类型。
可以通过对一个已经公开的方法使用IgnoreOperationAttribute属性,来阻止这个方法的调用。
下面的表提供了数据 *** 作的签名:
query
Return value : Itenumerable<T>,Iqueryable<T>,ot entity
Parameters : Any number
name Prefix : Any name
Attribute : [query] (c#) or <query()>(VB)
Example : public Iqueryable<Product> GetProducts()
Update
Return value : None
Parameters : Entity
name Prefix : Update,Change,or Modify
Attribute : [Update]
Example : public voID UpdateProduct(Product product)
Insert
Return value : None
Parameters : Entity
name Prefix : Insert,Add,or Create
Attribute : [Insert]
Example : public voID InsertProduct(Product product)
Delete
Return value : None
Parameters : Entity
name Prefix : Delete or Remove
Attribute : [Delete]
Example : public voID DeleteProduct(Product product)
Resolve
Return value : Boolean
Parameters : Current entity,Original entity,Store entity,Boolean
name Prefix : Resolve
Attribute : [Resolve]
Example : public bool ResolveProduct( Product currentProduct,Product orininalProduct,Product storeProduct,bool deleteOperation)
Invoke
Return value : any
Parameters : any
name Prefix : any
Attribute : [Invoke]
Example :
[Invoke]
public decimal GetCompetitorsPrice(Product product)
named Update
Return value : None
Parameters : entity,any number of other parameters
name Prefix : 任何名字,只要和插入、更新、删除等 *** 作的名字前缀不同即可。
Attribute : [Update(UsingCustomMethod=true]
Example :
[Update(UsingCustomMethod=true]
public voID discontProduct(Product product,int percentage)
添加应用逻辑到Domain Service
在定义了要公开的数据 *** 作之后,就可以把所需的应用逻辑添加到domain service类了。可以直接把逻辑添加到 *** 作方法中,也可以添加到 *** 作方法可调用的其他方法中。
WCF 和 Domain Services
domain service是建立在WCF概念上的。domain service保留了下面的特点:
WCF Service的标准使用方式。 以有的WCF编程模型结构,例如 *** 作合约, *** 作行为,以及服务行为。 标准的WCF定制功能,例如绑定配置、行为配置等domain context和domain service的交流是通过使用WCF ChannelFactory创建一个通道,并向它传递一个从domain service生成的服务合约。
总结以上是内存溢出为你收集整理的Silverlight WCF RIA服务(八)Domain Services 1全部内容,希望文章能够帮你解决Silverlight WCF RIA服务(八)Domain Services 1所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)