我试图从它所在的同一个项目中调用一个 asp.net webservice:
[MethodImpl(MethodImplOptions.Synchronized)]
public static void OnFileCreated(object source, FileSystemEventArgs e) {
trackdata_analyse rWebAnalyse = new trackdata_analyse();
rWebAnalyse.Analyse(@"pending\" + e.Name, "YOUNIVATE");
}
但是,当从 web 服务调用 Server.MapPath 时,我总是得到以下“ HttpContext 不可用。此类只能在 ASP.NET 请求的上下文中使用。 ”
[WebMethod]
public int Analyse(string fileName, string PARSING_MODULE){
int nRecords;
TrackSession rTrackSession = new TrackSession() ;
string filePath = Server.MapPath(@"..\data\") + fileName;
尽管 web 服务在同一个项目中,但我是否必须添加 WebReference?