2012-06-11 69 views

回答

4

感谢您的帮助,我能够为多个平台创建的文件上传WCF休息服务。

public void FileUpload(string fileName, Stream fileStream) 
{ 
    FileStream fileToupload = new FileStream("c:\\FileUpload\\" + fileName, FileMode.Create); 

    byte[] bytearray = new byte[10000]; 
    int bytesRead, totalBytesRead = 0; 
    do 
    { 
     bytesRead = fileStream.Read(bytearray, 0, bytearray.Length); 
     totalBytesRead += bytesRead; 
    } while (bytesRead > 0); 

    fileToupload.Write(bytearray, 0, bytearray.Length); 
    fileToupload.Close(); 
    fileToupload.Dispose(); 
} 

[ServiceContract] 
public interface IImageUpload 
{ 
    [OperationContract] 
    [WebInvoke(Method = "POST", UriTemplate = "FileUpload/{fileName}")] 
    void FileUpload(string fileName, Stream fileStream); 
} 
+0

感谢这个..你可以请发表您用来上传图片到该代码Android的代码? –

+0

你能告诉我去访问来自Android设备此服务 –

2

任何Rest service可以使用Android,iPhone和WP7进行访问。

一个选项是使用WCFMVC创建Rest POST服务,并以data作为base64字符串获取图像。