郁闷了一下午的一个问题,帮忙看看
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程序中。