我正在开发window phone 7应用程序。我正在使用XML文件来存储&检索窗口电话7应用程序的数据。在我的应用程序中,我创建了当前窗口phone 7应用程序的类库。我有'CoreClassLayer','DataAccessLayer'&'BusinessLayer'labraries为我目前的应用程序。在CoreObjectLayer类库我使用下面的代码为一类,如下所示(对于如范畴类)开发WCF服务应用程序时应该遵循哪种体系结构?
public class Category
{
public int ID { get; set; }
public String Name { get; set; }
public int TransactionType_ID { get; set; }
public Category()
{
}
public Category(int ID, String Name, int TransactionType_ID)
{
this.ID = ID;
this.Name = Name;
this.TransactionType_ID = TransactionType_ID;
}
public Category(XElement xElement)
{
ID = Convert.ToInt32(xElement.Element("ID").Value.ToString());
Name = xElement.Element("Name").Value;
TransactionType_ID = Convert.ToInt32(xElement.Element("TransactionType_ID").Value.ToString());
}
public XElement Information
{
get
{
return new XElement("Category",
new XElement("ID", ID),
new XElement("Name", Name),
new XElement("TransactionType_ID", TransactionType_ID));
}
}
}
在DataAccessLayer我使用下面的代码为一个类(如所属分类类)
public class CategoryList : List<Category>
{
public void GetCategoryObjects(params int [] TransactionType_ID)
{
int TransactionType_ID_Val = TransactionType_ID.Count();
XDocument doc = null;
XMLFileManager XMLDocObj = new XMLFileManager();
doc = XMLDocObj.LoadXMLFile("Categories.xml");
if (TransactionType_ID_Val == 0)
{
var vAllCategories = from s in doc.Descendants("Category")
select new Category(s);
this.Clear();
AddRange(vAllCategories);
}
else
{
var vCategories = from s in doc.Descendants("Category")
.Where(x => x.Element("TransactionType_ID").Value == TransactionType_ID[0].ToString())
select new Category(s);
this.Clear();
AddRange(vCategories);
}
}
在我BusinessLayer我使用下面的代码为一个类(如CategoryManager类)
public CategoryList GetCategories(params int [] TransactionType_ID)
{
CategoryList m_dbList = new CategoryList();
m_dbList.GetCategoryObjects(TransactionType_ID);
return m_dbList;
}
public List<String> LoadCategories(params int [] TransactionType_ID)
{
CategoryManager CategoryManagerObj = new CategoryManager();
CategoryList CategoryListObj = new CategoryList();
List<String> CategoryNames = new List<string>();
CategoryListObj = CategoryManagerObj.GetCategories(TransactionType_ID);
foreach (Category vCategory in CategoryListObj)
{
CategoryNames.Add(vCategory.Name);
}
return CategoryNames;
}
现在我使用的业务层,以创造e我的移动应用程序的用户界面层。现在我想把以上三层 - CoreLayer,DataAccessLayer & BusinessLayer逻辑放入WCF Web服务中。我想从我的WCF服务公开方法LoadCategories()。与上述情况类似,我想公开WCF服务中的不同方法。那么我应该遵循什么架构?我应该在当前WCF服务应用程序的CoreObjectlayer中添加'WCF服务库'以及DataAccessLayer的'WCF服务库'到WCF服务应用程序&,我当前的WCF服务应用程序将充当业务层?这是正确的路吗?或者我应该继续使用当前的WCF服务应用程序,而不使用任何'WCF服务库'&单一方法LoadCategories()包含所有三层中包含的逻辑?还是有其他方法吗?你能提供我解决上述问题的任何解决方案或链接吗?如果我做错了什么,请指导我。