gpt4 book ai didi

c# - 如何知道 .net WebMethod 何时返回其值?

转载 作者:太空宇宙 更新时间:2023-11-03 16:42:01 25 4
gpt4 key购买 nike

我是 c# Web 服务的新手。我有一个将返回大量数据的 WebMethod。因此应该可以查看传输的状态。我怎么知道 WebMethod 是否以及何时返回了它的值?我可以绑定(bind)到事件或其他东西吗?

有问题的方法如下所示:

[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();
}

最佳答案

服务器端:
使用日志记录或将列表写入 nrmal 文件,如下所示:

[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 并将结果写入文件。

关于c# - 如何知道 .net WebMethod 何时返回其值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7204488/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com