WCF 流式传输花费的时间太长
我已经在代码中启用了流式传输,但上传大文件仍然需要很长时间。发生的情况如下:
我的 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>
I have enabled streaming in my code but still its taking long time to upload large files. Here is what happens :
My WPF code calls the service to upload the file but the debugger on the service is hit after a long time. For 10 MB file, it takes approx 1.07 mins.
Following is the code :
Calling code :
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);
}
Operation Contract :
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过编辑托管 WCF 服务的 Web 应用程序的 Web.config 在服务合同级别对其进行优化。
为了给您指明正确的方向,我必须了解有关应用程序托管的 Web 服务等的更多信息。但这将类似于构建自定义绑定:
You can optimize it at the Service Contract level, by editing the Web.config of the Web application that hosts the WCF Service.
To point you in the right direction I would have to know a lot more information about the Web Services that the application hosts, etc. But it would be something along the lines of building a custom binding with: