0

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 メソッドを小さな文字列で実行すると、大きな文字列を持つ 2 番目のメソッドが機能し、WCF はそれを処理できます。

大きなデータを持つメソッドの前に別のメソッドを追加すると、413 Error Request Entity Too Large が消える理由がわかりましたか?

"CallMeBeforeAnyOtherCall()" などのダミー メソッドを使用して WCF 接続を開始する必要がありますか?

前もって感謝します

4

0 に答える 0