当前位置:编程学习 > C#/ASP.NET >>

如何创建一个WCF服务,提供客户端文件路径后上传指定文件到服务端?

public string UploadTransactionsFile(string uploadPath)
            {
                string uploadTransactionsFile;
    
                if (String.IsNullOrEmpty(uploadPath))
                    return string.Empty;
    
                if (!ValidateTransactionsFile(uploadPath))
                    return string.Empty;
    
                try
                {
                    var dir = @"C:\Upload\";
                    string myUploadPath = dir;
                    var myFileName = Path.GetFileName(uploadPath);
                    CheckDirectory(myUploadPath);
    
                    var client = new WebClient { Credentials = CredentialCache.DefaultCredentials };
    
                   client.UploadFile(myUploadPath + myFileName, "PUT", uploadPath);
                    client.Dispose();
    
    
                    uploadTransactionsFile = "ok";
                }
                catch (Exception ex)
                {
                    uploadTransactionsFile = ex.Message;
                }
    
                return uploadTransactionsFile;
            }

如果我这样写的话,把文件服务端放在远方就失败了,因为似乎这个client还是在server 端调用的。那我应该怎么做呢?网上有提供FileInfo作为参数的方法,但我这个题目要求一定要用string传递客户端的path作为参数 --------------------编程问答-------------------- http://blog.csdn.net/fangxing80/article/details/6164017
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,