通过 WCF 服务上传大于 8 MB 的流
Upload greater than 8 MB streams through WCF Service
我正在尝试使用 REST 配置 (webHttpBinding) 通过 window 服务上传照片(附件流),但出现此异常
这是我使用的绑定配置(我都试过了,错误依旧)
<webHttpBinding>
<binding name="maxRequest" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="64" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode ="Transport"></security>
</binding>
<binding name="maxRequestBinding" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" >
<readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode ="Transport">
</security>
</binding>
<binding name="BasicHttpBinding_IFileService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"
transferMode="Buffered" useDefaultWebProxy="true"
>
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode ="Transport"></security>
</binding>
我也尝试过此处发布的 IIS 解决方案
然而,上述所有方法都不起作用。
这是我的端点行为
<endpointBehaviors>
<behavior name="rest">
<webHttp faultExceptionEnabled="true" helpEnabled="true"/>
<dataContractSerializer maxItemsInObjectGraph="1365536" />
</behavior>
</endpointBehaviors>
这是合同
有关详细信息,图像大小仅为 100KB。
WCF默认传输消息大小为64KB,需要使用MaxReceivedMessageSize设置传输消息大小。
<system.serviceModel>
<services>
<service name="ConsoleApp1.RawDataService" behaviorConfiguration="ServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8012/ServiceModelSamples/service"/>
</baseAddresses>
</host>
<endpoint address=""
binding="webHttpBinding"
contract="ConsoleApp1.IReceiveData"
behaviorConfiguration="ESEndPointBehavior" bindingConfiguration="RestfullwebHttpBinding"/>
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="RestfullwebHttpBinding" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647" maxBufferSize="2147483647">
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="ESEndPointBehavior">
<webHttp helpEnabled="true"/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata/>
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
您需要将 RestfullwebHttpBinding 应用到端点。
如果问题仍然存在,请随时告诉我。
我正在尝试使用 REST 配置 (webHttpBinding) 通过 window 服务上传照片(附件流),但出现此异常
这是我使用的绑定配置(我都试过了,错误依旧)
<webHttpBinding>
<binding name="maxRequest" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="64" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode ="Transport"></security>
</binding>
<binding name="maxRequestBinding" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" >
<readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode ="Transport">
</security>
</binding>
<binding name="BasicHttpBinding_IFileService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"
transferMode="Buffered" useDefaultWebProxy="true"
>
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode ="Transport"></security>
</binding>
我也尝试过此处发布的 IIS 解决方案
然而,上述所有方法都不起作用。
这是我的端点行为
<endpointBehaviors>
<behavior name="rest">
<webHttp faultExceptionEnabled="true" helpEnabled="true"/>
<dataContractSerializer maxItemsInObjectGraph="1365536" />
</behavior>
</endpointBehaviors>
这是合同
有关详细信息,图像大小仅为 100KB。
WCF默认传输消息大小为64KB,需要使用MaxReceivedMessageSize设置传输消息大小。
<system.serviceModel>
<services>
<service name="ConsoleApp1.RawDataService" behaviorConfiguration="ServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8012/ServiceModelSamples/service"/>
</baseAddresses>
</host>
<endpoint address=""
binding="webHttpBinding"
contract="ConsoleApp1.IReceiveData"
behaviorConfiguration="ESEndPointBehavior" bindingConfiguration="RestfullwebHttpBinding"/>
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="RestfullwebHttpBinding" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647" maxBufferSize="2147483647">
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="ESEndPointBehavior">
<webHttp helpEnabled="true"/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata/>
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
您需要将 RestfullwebHttpBinding 应用到端点。
如果问题仍然存在,请随时告诉我。