I am developing window phone 7 application. I am using XML files for storing & retrieving data for the window phone 7 application. In my application I have created the class libraries for my current window phone 7 application. I have the 'CoreClassLayer' , 'DataAccessLayer' & 'BusinessLayer' labraries for my current application. In the CoreObjectLayer class library I am using the following code for one class as follows (for e.g Category class)
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));
}
}
}
In the DataAccessLayer I am using the following code for one class ( for e.g. CategoryList class)
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);
}
}
In my BusinessLayer I am using the following code for one class (for e.g. CategoryManager class)
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;
}
Now I am using the business layer to create the user interface layer of my mobile application. Now I want to put all above three layers - CoreLayer, DataAccessLayer & BusinessLayer logic into the WCF Web Service. I want to expose the method LoadCategories() from my WCF Service. Similarly to the above case I want to expose different methods from the WCF Service. So what architecture should I follow ? Should I add the 'WCF Service Library' in my current WCF Service application for CoreObjectlayer as well as 'WCF Service Library' for DataAccessLayer to the WCF Service Application & my current WCF Service Application will act as a business layer ?. Is this right way to go ? Or should I continue with my current WCF Service Application without any 'WCF Service Library' & single method LoadCategories() contain the logic included in all three layers ? Or Is there any other way ? Can you provide me any solution or link through which I can resolve the above issue ? If I am doing anything wrong then please guide me.
Without arguing the merits of the dozens of architectures you could use here- keep it simply and expose as little as you need.
If you simply need to return a set of data objects (Server.GetListOfPeanutButters()), then expose just "LoadCategories()"- you should really be thinking, "What do I really have to make public on my backend to get this to work" and everything else should, generally, not be exposed via the service.
Start there and evolve as needed- that'd be my advice.
精彩评论