我是C#Web服务的新手。我有一个WebMethod,它将返回大量数据。因此,应该可以查看传输状态。我如何知道WebMethod是否以及何时返回其值?我可以绑定事件吗?
有问题的方法如下所示:
[WebMethod]
public List<TEST.Models.ArticleModel> GetArticles(string terminalSerial)
{
Communication comm = new Communication {
StartDate = DateTime.Now,
Status = "Started"
};
var terminal = (from t in context.Terminals
where t.SerialNumber == terminalSerial
select t).FirstOrDefault();
var articles = from a in context.Articles
where a.CountryID == terminal.Customer.CountryID
&& a.LastEdit > terminal.LastSync
select new TEST.Models.ArticleModel {
ArticleID = a.ArticleID,
ArticleGroupID = a.ArticleGroupID,
ArticleGroupName = a.ArticleGroup.Name,
CountryName = a.Country.Name,
Description = a.Description,
EAN = a.EAN,
SAPID = a.SAPID
};
terminal.LastSync = DateTime.Now;
comm.TerminalID = terminal.TerminalID;
context.SubmitChanges();
return articles.ToList();
}
最佳答案
服务器端:使用日志记录或将列表写入普通文件,如下所示:
[WebMethod]
public List<TEST.Models.ArticleModel> GetArticles(string terminalSerial)
{
//..... your code here
System.IO.StreamWriter file = new System.IO.StreamWriter("c:\\test.txt");
List<TEST.Models.ArticleModel> theList = articles.ToList();
file.WriteLine("you have "+ theList.Count );
for(ArticleModel articleModel : theList)
file.WriteLine(articleModel.ToString());
file.Close();
}
在客户端也是如此,调用WebService并将结果写入File。
关于c# - 如何知道.net WebMethod何时返回其值?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7204488/