我现在是要做一个调用图片的web service,代码如下:
[WebMethod]    public byte[] GetImage()
    {
        return getBinaryFile(@"C:\Inetpub\wwwroot\myService\CentralPark.jpg");
    }
    public byte[] getBinaryFile(string filename)
    {
        if (File.Exists(filename))
        {
            try
            {
                FileStream s = File.OpenRead(filename);
                return ConvertStreamToByBuffer(s);            }
            catch (Exception e)
            {
                return new byte[0];
            }        }
        else
        {
            return new byte[0];
            
        }
    }
    public byte[] ConvertStreamToByBuffer(System.IO.Stream theStream)
    {
        int b;
        System.IO.MemoryStream tempStream = new System.IO.MemoryStream();
        while ((b = theStream.ReadByte()) != -1)
        {
            tempStream.WriteByte(((byte)b));        }
        return tempStream.ToArray();
    }
服务器是本机IIS,其中的图片地址(C:\Inetpub\wwwroot\myService\CentralPark.jpg)是图片在IIS中的地址,我在网上弄了一个空间,想把服务发布到网上,可是我的图片地址应该怎么写?
网站根目录文件如下:
App_code文件夹, App_Data文件夹,web.config文件,Service.asmx文件,a.jpg图片,
在程序中我应该怎么取图片的地址?

解决方案 »

  1.   

    try:string fileName = HttpContext.Server(@"/") + @"/a.jpg";
      

  2.   

    string fileName = HttpContext.Current.Server(@"/") + @"/a.jpg";
      

  3.   

    BearRui(AK-47):你说的有错误:"System.Web.HttpContext.Server"是"属性",但此处被当做方法来使用
    string fileName = HttpContext.Current.Server(@"/") + @"/a.jpg";
      

  4.   

    string fileName = Server.MapPath(@"~/a.jpg");
      

  5.   

    string fileName = HttpContext.Current.Server.MapPath(@"/") + @"/a.jpg";