2013-02-07 40 views
0

我正在使用实体框架,我想通过wcf服务公开一些方法;通用WCF包装

我有这个功能(在CS页)

using (ICRMEntities oContext = RemClient.Create<ICRMEntities>())     
    oContext.FindByKey<DataLib.Models.CRM.ActivitySLA>("ActivitySLA", SLAID); 

这个函数的内容是

public static T FindByKey<T>(this IQueryable<T> oQuery, int keyValue) where T : EntityObject, ISimpleBaseClassMD 
     { 
      return oQuery.FindByKey<T>(keyValue, null); 
     } 

在WCF服务定义的接口为:

public interface ICRMEntities : IDisposable, IContextWithUser 
    T FindByKey<T>(string sObjectTypeCode, int keyValue, bool bRequestValue) where T : EntityObject, ISimpleBaseClassMD; 

有WCF中这个泛型方法的问题; 如何包装这个方法来保存这个功能?

回答

3

你不行。

无法公开通过WCF服务的通用方法。您需要定义将使用的类型。这是SOAP的限制。

但是,你可以创建一个基类返回类型,并添加KnownType属性的服务来定义它的派生类此服务可以返回。

东西相似;

[KnownType(typeof(SomeClass))] 
public interface ICRMEntities : IDisposable, IContextWithUser 
    EntityObject FindByKey(string sObjectTypeCode, int keyValue, bool bRequestValue)