我在 WCF 4.0 上遇到 413 Request Entity Too Large 错误。
这是服务器 web.config 文件:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="WCFAuthenticationBehavior">
<serviceCredentials>
<serviceCertificate storeLocation="LocalMachine" x509FindType="FindBySubjectName" findValue="wcfauthentication.local" />
</serviceCredentials>
<serviceMetadata httpGetEnabled="False" httpsGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="True"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding maxBufferSize="2147483647"
maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" transferMode="Streamed" >
<readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
<binding name="customBasicHttpBinding" maxBufferSize="2147483647"
maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" transferMode="Streamed">
<readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="Transport">
<transport clientCredentialType="Certificate" />
</security>
</binding>
</basicHttpBinding>
<basicHttpsBinding>
<binding maxBufferSize="2147483647"
maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" transferMode="Streamed" >
<readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
<binding name="customBasicHttpsBinding" maxBufferSize="2147483647"
maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" transferMode="Streamed" >
<readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="Transport">
<transport clientCredentialType="Certificate" />
</security>
</binding>
</basicHttpsBinding>
<wsHttpBinding>
<binding maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647" >
<security mode="Transport">
<transport clientCredentialType="Certificate" />
</security>
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647"/>
</binding>
<binding name="customBasicWsHttpBinding" maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647">
<security mode="Transport">
<transport clientCredentialType="Certificate" />
</security>
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647"/>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service name="WCF_SEM_TSS.ServiceWCFAuthentication" behaviorConfiguration="WCFAuthenticationBehavior">
<host>
<baseAddresses>
<add baseAddress="https://wcfauthentication.local/ServiceWCFAuthentication.svc/"/>
</baseAddresses>
</host>
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="customBasicWsHttpBinding"
contract="WCF_SEM_TSS.IWCFAuthentication">
</endpoint>
</service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true">
<serviceActivations>
<add service="WCF_SEM_TSS.ServiceWCFAuthentication" relativeAddress="ServiceWCFAuthentication.svc" />
</serviceActivations>
</serviceHostingEnvironment>
</system.serviceModel>
这是客户端 web.config 文件:
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="WCFAuthenticationBehavior">
<clientCredentials>
<clientCertificate storeLocation="CurrentUser" x509FindType="FindBySubjectName" findValue="ClientWCFAuthentification" />
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="customWsHttpBinding" maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647">
<security mode="Transport">
<transport clientCredentialType="Certificate" />
</security>
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647"/>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="https://wcfauthentication.local/ServiceWCFAuthentication.svc/"
behaviorConfiguration="WCFAuthenticationBehavior"
binding="wsHttpBinding" bindingConfiguration="customWsHttpBinding"
contract="WCFAuthentification.IWCFAuthentication" name="MyEndPoint" />
</client>
</system.serviceModel>
当我启动这部分代码时:
String strEndPointAddress = "https://wcfauthentication.local/ServiceWCFAuthentication.svc";
var remoteAddress = new EndpointAddress(strEndPointAddress);
_wcf = new WCFAuthenticationClient("MyEndPoint", "https://wcfauthentication.local/ServiceWCFAuthentication.svc");
//result = _wcf.MyMethod("1", "test", LargeString.Substring(0,100), "Data1");
result = _wcf.MyMethod("1", "test", LargeString, "Data1");
我得到了错误。但是,当我在该部分添加注释行并使用较小的字符串执行 MyMethod 方法时,使用大字符串的第二种方法有效,WCF 可以处理它。
您知道为什么当我在具有大数据的方法之前添加另一种方法时,413 Error Request Entity Too Large 会消失吗?
是否有必要使用诸如“CallMeBeforeAnyOtherCall()”之类的虚拟方法来启动 WCF 连接?
提前致谢