Har*_*can 5 .net rest wcf post httpwebrequest
我创建了一个自托管的.NET服务,接受二进制上传.
[ServiceContract]
public interface IBinaryService
{
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "up/file/{fileName}/{hash}")]
void FileUpload(string fileName, string hash, Stream fileStream);
Run Code Online (Sandbox Code Playgroud)
当它收到文件时,它首先检查该文件是否已经在系统上,否则它从客户端流式传输文件并保存:
public void FileUpload(string fileName, string hash, Stream fileStream)
{
string filebasedir = basedir + @"file\"; //"
if (File.Exists(filebasedir + hash))
{
WebOperationContext.Current.OutgoingResponse.StatusCode =
System.Net.HttpStatusCode.Conflict;
return;
}
using(var fileToupload = new FileStream(
string.Concat(filebasedir, hash),
FileMode.Create))
{
fileStream.CopyTo(fileToupload);
}
Run Code Online (Sandbox Code Playgroud)
如果我单步执行代码,我可以看到文件内容在服务器读取参数并确定是否存在冲突之后才会进行流式处理.我只需要以某种方式强制服务器不读取全部内容(可能是几兆字节).不幸的是,使用'return'提前退出方法不会这样做.
这可能吗?
| 归档时间: |
|
| 查看次数: |
609 次 |
| 最近记录: |