Reputation: 12986
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.
Upvotes: 1
Views: 197
Reputation: 28530
Don't forget to decorate your DAL entites with [DataContract], if applicable.
Upvotes: 1