2012-06-11 38 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字符串獲取圖像。