我正在开发window phone 7应用程序。我正在使用XML文件存储&检索窗口电话7应用程序的数据。在我的应用程序中,我为当前的window phone 7应用程序创建了类库。我有'CoreClassLayer','DataAccessLayer'和&我当前应用程序的'BusinessLayer'工作流程。在CoreObjectLayer类库中,我对一个类使用以下代码,如下所示(例如,类别类)
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中,我对一个类使用以下代码(例如,对于CategoryList类)
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;
}
现在我正在使用业务层来创建移动应用程序的用户界面层。现在我想把所有三层以上 - CoreLayer,DataAccessLayer&amp; BusinessLayer逻辑进入WCF Web服务。我想从我的WCF服务公开方法LoadCategories()。与上述情况类似,我希望从WCF服务公开不同的方法。那么我应该遵循什么架构?我应该在我当前的CoreObjectlayer WCF服务应用程序中添加“WCF服务库”以及将DataAccessLayer的“WCF服务库”添加到WCF服务应用程序&amp;我当前的WCF服务应用程序将充当业务层?这是正确的方法吗?或者我应该继续使用当前的WCF服务应用程序而不需要任何“WCF服务库”和单个方法LoadCategories()包含所有三个层中包含的逻辑?或者还有其他方法吗?您能否为我提供解决上述问题的任何解决方案或链接?如果我做错了什么,请指导我。
答案 0 :(得分:0)
在不论证您可以在这里使用的数十种架构的优点的情况下 - 保持简单并尽可能少地暴露。
如果你只需要返回一组数据对象(Server.GetListOfPeanutButters()),那么只展示“LoadCategories()” - 你应该真的在想,“我真的需要在我的后端公开让这个工作“并且其他一切通常都不应该通过服务公开。
从那里开始,根据需要进化 - 这是我的建议。