是这样的,我要在CS下发送一个图片,在BS接受然后保存在本地,我一想,就只能通过URL传递啦,请问各位高手,该肿么办,我的思路是这样的,就是先把图片转为字节流通过URL传到BS下,然后Request接受转为图片再保存

解决方案 »

  1.   

        /// <summary>
            /// 获取更新软件路径及详细信息(服务端)
            /// </summary>
            /// <returns></returns>
            [WebMethod(Description = "在线更新软件")]
            public string GetUpdateData()
            {
                //取得更新的xml模板内容
                XmlDocument doc = new XmlDocument();
                doc.Load(Server.MapPath("update.xml"));
                XmlElement root = doc.DocumentElement;
                
                //看看有几个文件需要更新
                XmlNode updateNode = root.SelectSingleNode("filelist");
                string path = updateNode.Attributes["sourcepath"].Value;
                int count = int.Parse(updateNode.Attributes["count"].Value);
                
                //将xml中的value用实际内容替换
                for (int i = 0; i < count; i++)
                {
                    XmlNode itemNode = updateNode.ChildNodes[i];
                    string fileName = path + itemNode.Attributes["name"].Value;
                    FileStream fs = File.OpenRead(Server.MapPath(fileName));
                    itemNode.Attributes["size"].Value = fs.Length.ToString();                itemNode.Attributes["prefect"].Value = "0";
                    //为V2.4.3升级准备
                    BinaryReader br = new BinaryReader(fs);                //这里是文件的实际内容,使用了Base64String编码
                    //itemNode.SelectSingleNode("value").InnerText = Convert.ToBase64String(br.ReadBytes((int)fs.Length), 0, (int)fs.Length);
                    br.Close();
                    fs.Close();
                }
                return doc.InnerXml;
            }
      

  2.   

    //客户端处理  XmlDocument doc = new XmlDocument();
                doc.Load(Application.StartupPath + @"\update.xml");
                XmlElement root = doc.DocumentElement;
                //取需要下载的文件列表
                XmlNode updateNode = root.SelectSingleNode("filelist");
                string _Version = root.SelectSingleNode("version").InnerText;
                string path = updateNode.Attributes["sourcepath"].Value;
                int count = int.Parse(updateNode.Attributes["count"].Value);
                for (int i = 0; i < count; i++)
                {
                    XmlNode itemNode = updateNode.ChildNodes[i];
                    //从单独的download文件
                    string fileName = Application.StartupPath + @"\download\" + itemNode.Attributes["name"].Value;
                    
                    string fileRealName = itemNode.Attributes["name"].Value;//取到XML中文件
                    string[] items = fileRealName.Split(new char[] { '.' });                //对压缩的文件解压缩 单独处理
                    if (items[items.Length-1] == "zip")
                    {
                        try
                        {
                            string name = Path.GetFileNameWithoutExtension(fileRealName);//去掉                        //删除在根目录下的下载文件
                            fi = new FileInfo(Application.StartupPath + @"\" + name);
                            fi.Delete();
                            //将下载在download中文件拷到根目录下
                            File.Copy(fileName, Application.StartupPath + @"\" + name + ".zip");
                            //解压缩
                            DecompressFile(Path.GetFileName(fileRealName), name);
                            //解压完成删除压缩包
                            fi = new FileInfo(Application.StartupPath + @"\" + name + ".zip");
                            fi.Delete();
                            continue;
                        }
                        catch
                        {
                        }
                    }
                    if (fileRealName != "update.exe")
                    {
                        
                        try
                        {
                            //删除根路径文件
                            fi = new FileInfo(Application.StartupPath + @"\" + fileRealName);
                            fi.Delete();
                            File.Copy(fileName, Application.StartupPath + @"\" + fileRealName);
                        }
                        catch 
                        {
                        }
                    }
      

  3.   

    理论上是可行的.
    不过当遇到稍大一点的文件时,字符长度就长了.而一般的浏览对Url长度是有限制的.所以你的方案行不通的.以所以最好POST过去就行了.使用WebClient 最简单有个什么Upload就行了.
      

  4.   

    刚写了一个比较简单的代码.
            public string Upload(string url, string fileName)
            {
                WebClient webClient = new WebClient();
                byte[] rcv = webClient.UploadFile(url, "POST", fileName);
                return Encoding.UTF8.GetString(rcv);
            }
      

  5.   

     将图片生成的字节数存在XML文件中 客户端然后解析