C# WCF使用MTOM上传50Mg文件
使用WCF上传50MG文件的最佳方式是什么 我以为MTOM会自动处理这个问题。C# WCF使用MTOM上传50Mg文件,c#,wcf,mtom,C#,Wcf,Mtom,使用WCF上传50MG文件的最佳方式是什么 我以为MTOM会自动处理这个问题。 我想我错了 即使在本地主机上运行,也会发生异常 (我假设使用外部IIS将是最糟糕的) 异常消息: “接收对的HTTP响应时出错 .这可能是因为 未使用HTTP协议的服务端点绑定。这也可能 可能是由于服务器中止了HTTP请求上下文 (可能是由于服务关闭)。有关详细信息,请参阅服务器日志 细节。” 服务器配置: <system.serviceModel> <client>
我想我错了 即使在本地主机上运行,也会发生异常
(我假设使用外部IIS将是最糟糕的) 异常消息: “接收对的HTTP响应时出错 .这可能是因为 未使用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>
客户端配置:
<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>
感谢您的高级支持。如果文件正好是50MB,那么您的maxReceivedMessageSize和maxArrayLength设置得太低,因为50MB实际上是50*1024*1024=52428800字节。此外,maxReceivedMessageSIze必须考虑消息本身的结构(SOAP信封等),而不仅仅是数据
您可以使用流式处理,这是建议的处理大文件的方法。不幸的是,wsHttpBinding无法使用它,您可能需要使用basicHttpBinding或webHttpBinding之类的工具来启用流式传输
有关流媒体的更多信息,请点击此处:
另一方面,50兆千兆将相当大。不管是什么单位。