10

次のエラーで問題が発生します:「着信メッセージの最大メッセージサイズクォータ(65536)を超えました。クォータを増やすには、適切なバインディング要素でMaxReceivedMessageSizeプロパティを使用してください。

そこで、調査を行ったところ、バッファとメッセージのサイズを増やす必要があることがわかりました。WCFサービスの構成ファイルは次のとおりです。

<system.serviceModel>
    <bindings>
      <wsHttpBinding>
          <binding name="default" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"/>
      </wsHttpBinding>
    </bindings>
    <services>
      <service name="WCF.Service.Service">
        <endpoint address="ws" name="ws" bindingConfiguration="default" binding="wsHttpBinding" contract="WCF.Service.Contracts.IService" />
        <endpoint address="mex" binding="mexHttpBinding" name="mex" contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, 
          set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="True" />
          <!-- To receive exception details in faults for debugging purposes, 
          set the value below to true.  Set to false before deployment 
          to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="True" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

WCFテストクライアントでサービスを実行し、生成されたクライアント構成ファイルを確認すると、バインディングがありません。

<configuration>
<system.serviceModel>
    <bindings>
        <wsHttpBinding>
            <binding name="ws" closeTimeout="00:01:00" openTimeout="00:01:00"
                receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false"
                transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                messageEncoding="Text" 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="Message">
                    <transport clientCredentialType="Windows" proxyCredentialType="None"
                        realm="" />
                    <message clientCredentialType="Windows" negotiateServiceCredential="true"
                        algorithmSuite="Default" />
                </security>
            </binding>
        </wsHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://localhost:37444/Service.svc/ws" binding="wsHttpBinding"
            bindingConfiguration="ws" contract="IService" name="ws">
            <identity>
                <userPrincipalName value="username@domain" />
            </identity>
        </endpoint>
    </client>
</system.serviceModel>

バインディング構成が適用されない理由に迷いました!?WCFテストクライアントは、構成も常に再生成するように設定されています。また、消費しているフロントエンドアプリケーションでサービス参照を更新しようとしましたが、更新されたバインディング構成も取得されません。任意の提案をいただければ幸いです。ありがとう!

4

2 に答える 2

11

WCF は、サーバーからすべての設定をインポートするわけではありません。それをオンにするスイッチもありません。多くの場合は理にかなっているかもしれませんが、すべての設定をサーバー側からクライアントに複製することは必ずしも良い考えではありません。

したがって、あなたの場合、そのバインディング構成をクライアント側のプロキシにも追加し、クライアント エンドポイントから参照する必要があります。

ワイヤの両端を制御する場合は、作業を少し楽にすることができます。バインド構成を別のファイルに外部化し、それを参照します。

したがって、bindings.config以下を含むファイルを作成します。

<?xml version="1.0" ?>
<bindings>
    <wsHttpBinding>
        <binding name="default" 
                 maxBufferPoolSize="2147483647" 
                 maxReceivedMessageSize="2147483647"/>
  </wsHttpBinding>
</bindings>

次に、そのファイルをサーバー プロジェクトとクライアント プロジェクトの両方にコピーし、サービスとクライアントの構成内から参照できます。

<system.serviceModel>
    <bindings configSource="bindings.config" />
    <services>
      <service name="WCF.Service.Service">
        <endpoint address="ws" name="ws" bindingConfiguration="default" binding="wsHttpBinding" contract="WCF.Service.Contracts.IService" />
        <endpoint address="mex" binding="mexHttpBinding" name="mex" contract="IMetadataExchange" />
      </service>
    </services>

そしてあなたのクライアント側で:

<system.serviceModel>
    <bindings configSource="bindings.config" />
    <client>
        <endpoint  name="ws"
            address="http://localhost:37444/Service.svc/ws" 
            binding="wsHttpBinding"
            bindingConfiguration="default" 
            contract="IService">
            <identity>
                <userPrincipalName value="username@domain" />
            </identity>
        </endpoint>
    </client>
</system.serviceModel>

そうすれば、バインディングの設定を 1 回行うだけで、両方の場所で使用できます。

于 2010-10-27T18:11:22.347 に答える
2

maxBufferPoolSize と maxReceivedMessageSize はクライアントには公開されず、サーバーのみがそれらを認識します。クライアントが使用しているサイズはデフォルトです。必要なサイズに変更してください。あなたがそれをたくさん再生成しているなら明らかにこれは問題ですが、私は多くの代替手段があるとは思いません.

于 2010-10-27T18:08:11.477 に答える