[英]WCF Restful service file upload with multi-platform support
有人可以告诉我如何创建WCF Rest服务,通过它我可以使用android,iphone和WP7将文件上传到服务器。
感谢您的帮助,我能够为多个平台创建文件上传wcf rest服务。
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);
}
可以使用Android,iphone和WP7访问任何Rest service
。
一种选择是创建利用休息POST服务WCF
或MVC
和获取图像data
为base64字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.