我有一个 SilverLight 应用程序,它通过 SSL 通过 POST 调用 WCF 服务并发送大请求。使用自签名证书在本地机器上一切正常。此外,它可以在远程服务器上运行,但仅用于小请求。当应用程序为大范围数据发出 POST 请求(使用 SOAP)时,我收到 CommunicationException:“远程服务器返回错误:NotFound。”使用完全相同的 web.config 文件(sql 连接字符串除外)的本地计算机上的相同用例可以正常工作。看来是IIS配置的问题。我试图调查 IIS 日志,但在日志记录内核拒绝请求之前没有找到任何关于请求的信息。我读过很多文章,其中人们提出了端点绑定(bind)的不同设置,尝试过但没有取得成功。 我的服务配置如下:
<system.web>
<httpRuntime maxRequestLength="2097151"/>
<!--...(other settings) -->
</system.web>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483647" />
</requestFiltering>
</security>
</system.webServer>
<system.serviceModel>
<services>
<!--... (other services)-->
<service name="SD.Web.Services.ClientUser.UserLayersService">
<endpoint address="soap"
binding="basicHttpBinding"
contract="SD.Web.Services.ClientUser.IUserLayersService" />
<endpoint address="json"
behaviorConfiguration="SD.Web.Services.AspNetAjaxBehavior"
binding="webHttpBinding"
contract="SD.Web.Services.ClientUser.IUserLayersService" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<bindings>
<webHttpBinding>
<binding maxReceivedMessageSize="2097152"
maxBufferSize="2097152"
maxBufferPoolSize="2097152">
<security mode="Transport" />
</binding>
</webHttpBinding>
<basicHttpBinding>
<binding maxReceivedMessageSize="2097152"
maxBufferSize="2097152"
maxBufferPoolSize="2097152">
<security mode="Transport" />
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="SD.Web.Services.AspNetAjaxBehavior">
<webHttp defaultBodyStyle="Bare"
defaultOutgoingResponseFormat="Json"
automaticFormatSelectionEnabled="false"
faultExceptionEnabled="true" />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
最佳答案
我使用 Fiddler 4 找到了答案。必须设置读者配额。
<bindings>
<webHttpBinding>
<binding maxReceivedMessageSize="2097152"
maxBufferSize="2097152"
maxBufferPoolSize="2097152">
<readerQuotas maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647"/>
<security mode="Transport" />
</binding>
</webHttpBinding>
<basicHttpBinding>
<binding maxReceivedMessageSize="2097152"
maxBufferSize="2097152"
maxBufferPoolSize="2097152">
<readerQuotas maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647"/>
<security mode="Transport" />
</binding>
</basicHttpBinding>
</bindings>
关于WCF SOAP 服务对于大型请求返回 Not Found,对于较小的请求工作正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31810415/