谁能告诉我如何创建一个 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);
}
关于c# - 多平台支持的 WCF Restful 服务文件上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10978961/