我已在我的代码中启用了流媒体,但仍需要很长时间才能上传大文件。以下是发生的事情:
我的WPF代码调用服务来上传文件,但很长一段时间后服务器上的调试器被命中。对于10 MB文件,大约需要1.07分钟。
以下是代码:
致电代码:
using (System.IO.FileStream stream = new System.IO.FileStream(fileInfo.FullName, System.IO.FileMode.Open, System.IO.FileAccess.Read))
{
uploadRequestInfo.FileName = fileInfo.Name;
uploadRequestInfo.Length = fileInfo.Length;
uploadRequestInfo.FileByteStream = stream;
clientUpload.UploadFile(uploadRequestInfo);
}
运营合同:
public partial class RemoteFileInfo {
[System.ServiceModel.MessageHeaderAttribute(Namespace="http://tempuri.org/")]
public string FileName;
[System.ServiceModel.MessageHeaderAttribute(Namespace="http://tempuri.org/")]
public long Length;
[System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://tempuri.org/", Order=0)]
public System.IO.Stream FileByteStream;
public RemoteFileInfo() {
}
public RemoteFileInfo(string FileName, long Length, System.IO.Stream FileByteStream) {
this.FileName = FileName;
this.Length = Length;
this.FileByteStream = FileByteStream;
}
}
app.config:
<binding name="BasicHttpBinding_ITransferService" closeTimeout="00:10:00"
openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Streamed"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
答案 0 :(得分:0)
您可以通过编辑承载WCF服务的Web应用程序的Web.config来在服务合同级别对其进行优化。
为了指出正确的方向,我必须知道有关应用程序托管的Web服务的更多信息,等等。但是,这将是构建自定义绑定的方法: