0

バイト配列を取るデータ サービスがあります。次に、そのデータ サービスにファイルを送信しようとする Web ページがあります。ファイルが小さい場合 (たとえば 50kb)、すべてが期待どおりに機能しますが、ファイルが大きい場合 (100kb を超えるもの) は、データ サービスの保存変更呼び出しで "BadRequest" エラー メッセージが表示されます。

より大きなデータ サイズをデータ サービスに渡す方法はありますか?

編集 (詳細): maxRequestLength を高く設定し、webHttpBinding を試して maxReceivedMessageSize を増やしましたが、これらは役に立たないようです。

4

2 に答える 2

5

WCF サービスが処理できる要求の最大サイズは、WCF バインディングの MaxReceivedMessageSize プロパティによって制御されます。デフォルト値は 65536 で、これを超えると 400 応答コードが返されます。

サービスをホストする Web サイトの web.config で、セクションに次のノードを追加します。

<system.serviceModel> 
<services> 
  <!-- The name of the service --> 
  <service name="NorthwindService"> 
    <!-- you can leave the address blank or specify your end point URI --> 
    <endpoint address ="YourServiceEndpoint" 
              binding="webHttpBinding" bindingConfiguration="higherMessageSize" 
     contract ="System.Data.Services.IRequestHandler"> 
    </endpoint> 
  </service> 
</services> 
<bindings> 
  <webHttpBinding> 
    <!-- configure the maxReceivedMessageSize  value to suit the max size of 
         the request ( in bytes ) you want the service to recieve--> 
    <binding name="higherMessageSize" maxReceivedMessageSize ="MaxMessageSize"/> 
  </webHttpBinding> 
</bindings> 
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/> 
</system.serviceModel>

IIS でホストされている場合、ASP.Net 要求サイズの制限により、大きな要求が拒否される可能性もあります。HttpRuntimeSection.MaxRequestLength プロパティを設定する必要があります。

<system.web> 
  <httpRuntime MaxRequestLength="ValueInKiloBytes" />
</system.web>

WCF が、HTTP レベルで表示されていないカバーの下で例外をスローしているかどうかを特定します。サーバー側で WCF トレースを構成して、WCF レイヤーから必要な情報をログに記録できます。トレースをセットアップし、失敗を再現したら、ログにこれらの例外メッセージのいずれかまたは両方が含まれているかどうかを確認します。

System.ServiceModel.ProtocolException
"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."

System.Web.HttpException
"Maximum request length exceeded."

ログにこのメッセージが含まれている場合は、エラーの原因がメッセージ サイズであることを確認し、それに応じてこの修正を適用してください。

PD:フォームは"POST"メソッドを使用する必要があることに注意してください。

于 2009-01-15T16:15:53.937 に答える
3

I also tried to edit the web.config file with no result. I still get same exception.

A solution which works for me was editing the machine.config file and add the following lines in the System.ServiceModel Node.

<standardEndpoints>
        <webHttpEndpoint>
            <standardEndpoint name="" maxReceivedMessageSize="16777216" maxBufferSize="16777216" />
        </webHttpEndpoint>
    </standardEndpoints>

I don't know if this is the right solution, but it works for me.

于 2011-04-13T11:44:30.200 に答える