通过服务公开数据对象?
我创建了一个 SOAP 服务,该服务应该通过 SubSonic 查询返回一个 Category 对象和一个 CategoryCollection。问题是我可以很好地返回数据的 DataTable,但是从服务返回的对象在内部是活动记录类型,而不是我的 DAL 实体。
例如,当我使用服务时,我看到 SOAPService.Category,但看不到 SOAPService.CategoryCollection(我应该能够看到 SOAPService.[所有其他数据实体],并且 SOAPService.Category 属于活动记录类型,并且不包含实际的类别属性。
通过我的 SubSonic DAL 生成定义的两个类
namespace TrainingWebService.DAL
{
/// <summary>
// Strongly-typed collection for the Category class.
/// </summary>
[Serializable]
public partial class CategoryCollection : ActiveList<Category, CategoryCollection>
{
.
.
.
都
/// <summary>
/// This is an ActiveRecord class which wraps the Categories table.
/// </summary>
[Serializable]
public partial class Category : ActiveRecord<Category>, IActiveRecord
{
.
.
.
存在于 TrainingWebService.ISOAPService.cs 中
:
使用 。 VRPCTrainingWebService.DAL;
命名空间TrainingWebService { // VRPC 训练 Web 服务 - 接口 [服务合同] 公共接口 ISOAPService {
<前><代码> [操作合同] 字符串 GetDBConnectionStringDetails(); 【运营合同】 字符串 ReturnSameString(字符串 someString); // // 数据库相关 // [OperationContract] // 类别 类别集合 GetAllCategories(); // 亚音速对象 【运营合同】 数据表 GetAllCategoriesAsDataTable(); 【运营合同】 数据表 GetCategoryAsDataTable(int id); 【运营合同】 类别 GetCategoryByID(int id); // 亚音速对象 【运营合同】 // 产品 产品集合 GetAllProducts(); 【运营合同】 产品 GetProductByID(int id); [OperationContract] // 供应商 供应商集合 GetAllSuppliers(); 【运营合同】 供应商 GetSupplierByID(int id); }}
在我的 SOAPService.cs 中,
public CategoryCollection GetAllCategories() // get a collection of all categories
{
return DataCaller.GetAllCategories();
}
public DataTable GetAllCategoriesAsDataTable()
{
return DataCaller.GetCategoriesAsDataTable();
}
public DataTable GetCategoryAsDataTable(int id)
{
return DataCaller.GetCategoryAsDataTable(id);
}
Here's a snip of the DataCaller code.
/// <summary>
/// Get all categories - returns a collection of categories
/// </summary>
/// <returns></returns>
public static CategoryCollection GetAllCategories()
{
categoryCollection =
DB.Select().From("Categories")
.ExecuteAsCollection<CategoryCollection>();
return categoryCollection;
}
public static DataTable GetCategoryAsDataTable(int id)
{
try
{
dtResults = new Select()
.Where(Category.Columns.CategoryID).IsEqualTo(id)
.From(Category.Schema)
.ExecuteAsCollection<CategoryCollection>().ToDataTable();
}
catch (Exception ex)
{
throw ex;
}
return dtResults;
}
我认为问题可能在于通过我的 Web 服务公开 *.DAL 实体,因此它们是可访问的。
我在我不久前构建的另一个解决方案中工作得很好,但由于某种原因我看不到我在这里缺少什么。
I created a SOAP service that is supposed to return a Category object and a CategoryCollection through a SubSonic query. The problem is that I can return a DataTable of data just fine, however the objects returned from the service are of active record type, internally, and not of my DAL entities.
For example when I consume the service, I see SOAPService.Category, but not SOAPService.CategoryCollection (I should be able to see SOAPService.[all other data entities], and the SOAPService.Category is of active record type, and doesn't contain the actual Category properties.
Both classes defined through my SubSonic DAL generation.
namespace TrainingWebService.DAL
{
/// <summary>
// Strongly-typed collection for the Category class.
/// </summary>
[Serializable]
public partial class CategoryCollection : ActiveList<Category, CategoryCollection>
{
.
.
.
and
/// <summary>
/// This is an ActiveRecord class which wraps the Categories table.
/// </summary>
[Serializable]
public partial class Category : ActiveRecord<Category>, IActiveRecord
{
.
.
.
These classes exist in the TrainingWebService solution.
TrainingWebService.ISOAPService.cs:
using VRPCTrainingWebService.DAL;
namespace TrainingWebService {
// VRPC Training Web Service - Interface
[ServiceContract]
public interface ISOAPService
{[OperationContract] string GetDBConnectionStringDetails(); [OperationContract] string ReturnSameString(string someString); // // Database-related // [OperationContract] // categories CategoryCollection GetAllCategories(); // SubSonic object [OperationContract] DataTable GetAllCategoriesAsDataTable(); [OperationContract] DataTable GetCategoryAsDataTable(int id); [OperationContract] Category GetCategoryByID(int id); // SubSonic object [OperationContract] // products ProductCollection GetAllProducts(); [OperationContract] Product GetProductByID(int id); [OperationContract] // suppliers SupplierCollection GetAllSuppliers(); [OperationContract] Supplier GetSupplierByID(int id); }
}
In my SOAPService.cs
public CategoryCollection GetAllCategories() // get a collection of all categories
{
return DataCaller.GetAllCategories();
}
public DataTable GetAllCategoriesAsDataTable()
{
return DataCaller.GetCategoriesAsDataTable();
}
public DataTable GetCategoryAsDataTable(int id)
{
return DataCaller.GetCategoryAsDataTable(id);
}
Here's a snip of the DataCaller code.
/// <summary>
/// Get all categories - returns a collection of categories
/// </summary>
/// <returns></returns>
public static CategoryCollection GetAllCategories()
{
categoryCollection =
DB.Select().From("Categories")
.ExecuteAsCollection<CategoryCollection>();
return categoryCollection;
}
public static DataTable GetCategoryAsDataTable(int id)
{
try
{
dtResults = new Select()
.Where(Category.Columns.CategoryID).IsEqualTo(id)
.From(Category.Schema)
.ExecuteAsCollection<CategoryCollection>().ToDataTable();
}
catch (Exception ex)
{
throw ex;
}
return dtResults;
}
I think the problem may be in exposing the *.DAL entities through my web service, so they are accessible.
I have this working just fine in another solution I built a while back, but for some reason I can't see what I'm missing here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果适用,不要忘记用 [DataContract] 装饰您的 DAL 实体。
DataContractAttribute 类
Don't forget to decorate your DAL entites with [DataContract], if applicable.
DataContractAttribute Class