读书人

郁闷了一下午的一个有关问题,帮忙看看

发布时间: 2011-12-21 23:56:01 作者: rapoo

郁闷了一下午的一个问题,帮忙看看
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
using System.Xml;
using System.Text;


namespace AppUpdate
{
public class AutoUpdate : System.Web.Services.WebService
{
public AutoUpdate()
{
//CODEGEN: This call is required by the ASP.NET Web Services Designer
InitializeComponent();
}


private IContainer components = null;

private void InitializeComponent()
{
}

protected override void Dispose( bool disposing )
{
if(disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}

[WebMethod(Description= "取得最新版本号 ")]
public string GetVer()
{
try
{
XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath( "update.xml "));
XmlElement root = doc.DocumentElement;

return root.SelectSingleNode( "version ").InnerText;
}
catch(Exception e)
{
string s = e.Message;
return " ";
}

}


}
}

在一winform调用这个webservice,执行到doc.Load(Server.MapPath( "update.xml "));
的时候出错:HttpContext is not available. This class can only be used in the context of an ASP.NET request.
到底怎么回事啊,没分了,见谅

[解决办法]
Server.MapPath只能用在web程序中。
[解决办法]
Server.MapPath不能用在winform程序里 错误提示已经告诉你了
[解决办法]
把出错提示的E文意思读懂 就知道问题所在了
[解决办法]
HttpContext is not available. This class can only be used in the context of an ASP.NET request.

Server.MapPath只能用在web程序中。

读书人网 >asp.net

热点推荐