【解決方法】MaxReceivedMessageSize は名前付き bindingConfiguration では機能しません


こんにちは、みんな、

WCF ストリーミング サービスに関する構成の問題に直面しています。 3 つの WCF サービスを自己ホストする Windows サービスがあります。そのうちの 1 つは、ストリームを使用してバイナリ コンテンツのアップロードとダウンロードを処理します。 周りのドキュメントには、設定する必要があると記載されています maxReceivedMessageSize より大きなメッセージを受信できるように、適切な数 (例: 2147483647) に設定しました。

サービス構成:

HTML
<service name="DocumentService" behaviorConfiguration="DatashopServiceBehavior">
        <endpoint contract="IDocumentService" address="DocumentService"
                  binding="basicHttpBinding" name="basicHttpBinding" bindingConfiguration=""
                  behaviorConfiguration="DatashopServiceEndpointBehavior"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8080/Datashop/Documents/"/>
          </baseAddresses>
        </host>
      </service>

バインディング構成:

HTML
<basicHttpBinding>
<binding name="" transferMode="Streamed" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
                        maxArrayLength="2147483647" maxBytesPerRead="2147483647"
                        maxNameTableCharCount="2147483647" />
        </binding>
</basicHttpBinding>

エンドポイントの bindingConfiguration 属性に空の文字列値があり、バインディング自体の name 属性に空の文字列があることに気付くでしょう。 これが私たちがそれを機能させる唯一の方法だからです。 バインディングに明示的に名前を付け、その名前を使用してエンドポイントから参照すると、maxReceivedMessageSize プロパティが設定されていないかのようになり、大きなバイナリ コンテンツによって WCF サービス トレース ビューアーに次のエラーが表示されます。

The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.

私の同僚は、ストリーミング サービスを分離し、リフレクションを使用して実行時に構成を検査し、maxReceivedMessageSize が正しく設定されていることを発見しましたが、どういうわけか適用されません。

空の文字列を使用してバインディング構成に名前を付けて参照することで現在の問題を解決できますが、根本的な問題は解決されず、同じサービスで異なるバインディングを使用して別のエンドポイントをセットアップしたい場合は、だ。

詳細情報: EndpointBehavior は WSDL をフラット化するための WCFExtras であり、サービス クライアントを使用していません。 ChannelFactory<T>

誰かが以前にこの問題を経験したことがありますか?それに対する解決策は何でしたか?

どんな助けでも大歓迎です。

解決策 1

問題は、hostservice 呼び出しでサービスを自己ホストしているという事実にあります。

host.AddDefaultEndpoints();

baseAddress を使用して愚かにもサービスを呼び出していました。

http://localhost:8080/Datashop/Documents/

それ以外の:

http://localhost:8080/Datashop/Documents/DocumentService/

私がまだ理解していないのは、サーバー側が bindingConfiguration 名に空の文字列を持っていたときになぜいまいましいことが機能したのかということですが、この段階では気にしません。 WCF のバグだと思い込んで構成の問題を追跡する過去 2 日間を忘れるために、首から大量のビールを注ぐことの​​方がはるかに重要です 😉

解決策 2

HTML
<bindings>
      <basichttpbinding>
        <binding name="FlightInventory_basicHttpBinding" closetimeout="00:20:00" opentimeout="00:20:00">
          receiveTimeout="00:20:00" sendTimeout="00:20:00" allowCookies="false"
          bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
          maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"
          textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true"
          messageEncoding="Text">
          <readerquotas maxdepth="2147483647" maxstringcontentlength="2147483647">
            maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <security mode="None">
            <transport clientcredentialtype="None" proxycredentialtype="None">
              realm="" />
            <message clientcredentialtype="UserName" algorithmsuite="Default" />
          </transport></security>
        </readerquotas></binding>
      </basichttpbinding>
    </bindings>
    <services>
      <service name="FlightInventoryService.FlightInventory" behaviorconfiguration="FlightInventoryService.ServiceBehaviour">
        <endpoint address="" binding="basicHttpBinding" bindingconfiguration="FlightInventory_basicHttpBinding" contract="FlightInventoryService.IFlightInventory">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <servicebehaviors>
        <behavior name="FlightInventoryService.ServiceBehaviour">
          <!-- 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" />
          <datacontractserializer maxitemsinobjectgraph="2147483647" />
        </behavior>
      </servicebehaviors>
    </behaviors>
    <protocolmapping>
      <add binding="basicHttpsBinding" scheme="https" />
    </protocolmapping>
    <servicehostingenvironment aspnetcompatibilityenabled="true" multiplesitebindingsenabled="true" />

解決策 3

この問題の簡単な解決策を見つけました

app.configで変数「maxReceivedMessageSize」を構成すると、うまくいきませんでした

私がしたことは、次のようにコードでそれを行うことでした:

ServiceX.Service1Client ServMyService = new ServiceX.Service1Client();
ServMyService.Endpoint.Address = 新しい System.ServiceModel.EndpointAddress(“http://ipaddress/Service1.svc”);
BasicHttpBinding binding1 = new BasicHttpBinding(“BasicHttpBinding_IService1”);
binding1.MaxReceivedMessageSize = 2147483647;
ServMyService.Endpoint.Binding = binding1;

コメント

タイトルとURLをコピーしました