zoukankan      html  css  js  c++  java
  • Silverlight WCF RIA服务(八)Domain Services 1

    Domain Services 是向客户端公开数据访问层的WCF Services。当我们创建一个domain services实例时,就指定了想要公开的实体类,以及这个domain Services所允许的数据操作。 DomainService类 和派生类 DomainService类是所有做为domain Services的服务类的基类。WCF RIA
      

    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生成的服务合约。

    Powered By D&J (URL:http://www.cnblogs.com/Areas/)
  • 相关阅读:
    JaunsGraph数据模型
    JanusGraph的schema及数据建模
    JanusGraph Server配置
    JanusGraph与Cassandra集成模式
    cassandra的primary key, partition key, cluster key,
    Predix Asset Service深度分析
    Predix中模型设计
    web工程中web.xml元素加载顺序以及配置实例
    Tomcat,Jboss,Glassfish等web容器比较选型
    intelliJ idea像eclipse一样在class中断点调试
  • 原文地址:https://www.cnblogs.com/Areas/p/2172158.html
Copyright © 2011-2022 走看看