在Web.config内的<system.web>节中加入
<httpRuntime maxRequestLength="10240000"/>
即可。
自己做个测试吧,我忘了maxRequestLength的值是什么单位了,反正不是B就是KB,好像是KB....:)
网上有许多支持大文件上传的自定义控件,说白了也就是这样做的。
不知道这样能不能给分~~~~~~
基于TCP协议的WCF传输大文件如何出现进度条RT.
比如传输50M的文件,
我能显示个进度条 2000Kb of 5000Kb 已传输40%.
有回复了加分.
------解决方案--------------------
不建议用WCF做文件传输
参考以下代码(VS2008下测试通过)
Service端:
C# codeusing System
using System.Collections.Generic
using System.Linq
using System.Text
using System.ServiceModel
using System.IO
using System.ServiceModel.Dispatcher
using System.ServiceModel.Description
using System.ServiceModel.Channels
namespace FSDownloadService
{
[MessageContract]
public class MyFileInfo
{
[MessageHeader]
public string FileName
[MessageHeader]
public long FileSize
[MessageBodyMember]
public Stream Stream
public MyFileInfo() { }
public MyFileInfo(Stream stream, string fileName, long fileSize)
{
this.Stream = stream
this.FileSize = fileSize
this.FileName = fileName
}
}
[MessageContract]
public class DownloadFileRequest
{
[MessageBodyMember]
public readonly string FileName
public DownloadFileRequest() { }
public DownloadFileRequest(string fileName)
{
this.FileName = fileName
}
}
[ServiceContract]
public interface IFileManager
{
[OperationContract]
MyFileInfo DownloadFile(DownloadFileRequest request)
}
[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
public class MyService : IFileManager
{
public MyFileInfo DownloadFile(DownloadFileRequest request)
{
FileInfo fi = new FileInfo(request.FileName)
MyFileInfo result = new MyFileInfo(File.OpenRead(request.FileName), request.FileName, fi.Length)
return result
}
}
public class MyHost
{
static ServiceHost host = null
public static void Open()
{
string baseAddress = "net.tcp://localhost:2008/FileService"
host = new ServiceHost(typeof(MyService), new Uri(baseAddress))
host.AddServiceEndpoint(typeof(IFileManager), GetTcpBinding(), "")
host.Open()
}
public static void Close()
{
if (host != null &&host.State == CommunicationState.Opened)
{
host.Close()
}
host = null
}
public static Binding GetTcpBinding()
{
NetTcpBinding binding = new NetTcpBinding()
binding.TransferMode = TransferMode.Streamed
binding.MaxReceivedMessageSize = int.MaxValue
return binding
}
}
}
Asp.Net 一般支持上传4MB大小文件,为实现上传超过4MB大小文件,Asp.Net项目需要调整配置(Web.Config)的httpRuntime节点。<httpRuntime maxRequestLength="40960" executionTimeout="1800" />
maxRequestLength:指定输入流缓冲阈值限制(以 KB 为单位)。此限制可用于防止拒绝服务攻击;例如,因用户向服务器发送大型文件而导致的拒绝服务攻击。
默认值为 4096 (4 MB)。
executionTimeout: 指定在被 ASP.NET 自动关闭前,允许执行请求的最大秒数。默认值110秒。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)