14

maxStringContentLength を 8192 より大きい値に変更する必要がありますが、成功していません。私の WCF サービスは、受信するデータの量が 8192 バイトを超える場合、例外を生成します。検索を使い果たしましたが、何も役に立たないようです。例外はサーバーから発生することを指摘しておく必要があります。サーバー上の WCF から直接生成された例外が表示されるため、クライアントのことは忘れてください。これが私のweb.config設定です:

<system.serviceModel>
  <behaviors>
    <serviceBehaviors>
      <behavior name="DevServiceBehavior" >
        <serviceMetadata httpGetEnabled="true" />
      </behavior>
    </serviceBehaviors>
  </behaviors>
  <services>
    <service name="DeveloperService"
             behaviorConfiguration="DevServiceBehavior" >
      <endpoint address="mtom"
                binding="basicHttpBinding"
                bindingConfiguration="Binding_DevService"
                contract="DeveloperService">
        <identity>
          <dns value="localhost"/>
        </identity>
      </endpoint>
      <endpoint contract="IMetadataExchange"
                binding="mexHttpBinding"
                address="mex" />
    </service>
  </services>
  <bindings>
    <basicHttpBinding>
      <binding name="Binding_DevService"
               messageEncoding="Mtom"
               openTimeout="00:02:00"
               sendTimeout="00:02:00"
               maxBufferPoolSize ="41943040"
               maxBufferSize="2147483647"
               maxReceivedMessageSize="2147483647">
        <readerQuotas maxDepth="500"
                      maxArrayLength="20000000"
                      maxStringContentLength="20000000" />
      </binding>
    </basicHttpBinding>
  </bindings>
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
                              multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
4

2 に答える 2

19

デフォルトでは、WCF の最新バージョンは実際にはデフォルトを設定し、json がデフォルトです。明確ではなかったのは、WCF が使用していた既定のバインドの種類です。それは webHttpBinding であることが判明しました。[WebGet] などのサービス メソッドに属性が適用されていることを示す Web 上の例も数多く見られます。このメソッドには、属性はまったく必要ありません。maxStringContentLength を有効にするには、バインディングと動作を正しくセットアップする必要があります。web.config ファイルの正しいエントリは次のとおりです。

<system.serviceModel>
  <behaviors>
    <endpointBehaviors>
      <behavior name="jsonBehavior">
        <enableWebScript />
      </behavior>
    </endpointBehaviors>
    <serviceBehaviors>
      <behavior name="DevServiceBehavior" >
        <serviceMetadata httpGetEnabled="true" />
      </behavior>
    </serviceBehaviors>
  </behaviors>
  <services>
    <service name="DeveloperService" behaviorConfiguration="DevServiceBehavior" >
      <endpoint address="" binding="webHttpBinding" contract="DeveloperService" bindingConfiguration="webHttpBindingDev" behaviorConfiguration="jsonBehavior">
        <identity>
          <dns value="localhost"/>
        </identity>
      </endpoint>
      <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
    </service>
  </services>
  <bindings>
    <webHttpBinding>
      <binding name="webHttpBindingDev">
        <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"  maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
      </binding>
    </webHttpBinding>
  </bindings> 
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
于 2011-08-17T13:21:21.777 に答える
4

クライアント側の設定も更新してください。Reader のクォータを に、その属性をバインディング セクションに設定します。

于 2011-08-15T21:00:40.380 に答える