WCF正在使用MTOM上载50Mg的文件
本文关键字:上载 50Mg 文件 MTOM WCF | 更新日期: 2023-09-27 18:26:42
使用WCF上传50MG文件的最佳方式是什么?
我以为MTOM会自动处理这个问题
我想我错了。。。
即使在LocalHost上运行,也会发生异常
(我认为使用外部IIS将是最糟糕的)。
异常消息:
"接收对的HTTP响应时出错http://localhost:7064/DataSyncService.svc.这可能是由于未使用HTTP协议的服务端点绑定。这也可能是由于服务器中止了HTTP请求上下文(可能是由于服务关闭)。有关详细信息,请参阅服务器日志详细信息。"
服务器配置:
<system.serviceModel>
<client>
<remove contract="IMetadataExchange" name="sb" />
</client>
<bindings>
<wsHttpBinding>
<binding name="DataSyncBinding" messageEncoding="Mtom" maxReceivedMessageSize ="50000000" maxBufferPoolSize="50000000">
<readerQuotas maxArrayLength="50000000" />
<security mode="None" />
</binding>
</wsHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="Server.DataSyncServiceBehavior" name="Server.DataSyncService">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="DataSyncBinding" name="DataSyncService"
contract="Server.IDataSyncService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="Server.DataSyncServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="false" />
</system.serviceModel>
客户端配置:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="DataSyncService" closeTimeout="00:05:00" openTimeout="00:05:00"
receiveTimeout="00:30:00" sendTimeout="00:30:00" bypassProxyOnLocal="false"
transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Mtom" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="None">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:7064/DataSyncService.svc"
binding="wsHttpBinding" bindingConfiguration="DataSyncService"
contract="DataSyncServiceReference.IDataSyncService" name="DataSyncService" />
</client>
</system.serviceModel>
提前感谢。
如果文件正好是50 MB,则您的maxReceivedMessageSize和maxArrayLength设置得太低,因为50MB实际上是50*1024*1024=552428800字节。此外,maxReceivedMessageSIze必须考虑消息本身的结构(SOAP信封等),而不仅仅是数据。
你可以使用流媒体,这是大文件的建议方式。不幸的是,它不能用于wsHttpBinding,您可能需要使用类似于basicHttpBinding或webHttpBinding的东西来启用流。
更多关于流媒体的信息:
http://msdn.microsoft.com/en-us/library/ms733742.aspx