6

WCF Web Api 4.0フレームワークを使用していて、maxReceivedMessageSizeが65,000エラーを超えました。

webconfigを次のように更新しましたが、WCF Web Apiを使用しているため、webHttpEndpointを使用しなくなったため、これはもう使用されていないと思いますか?

<standardEndpoints>
      <webHttpEndpoint>
        <!-- 
            Configure the WCF REST service base address via the global.asax.cs file and the default endpoint 
            via the attributes on the <standardEndpoint> element below
        -->
        <standardEndpoint name="" 
                          helpEnabled="true" 
                          automaticFormatSelectionEnabled="true"
                          maxReceivedMessageSize="4194304" />       

      </webHttpEndpoint>

新しいWCFWebAPIのMaxReceivedMessageSizeはどこで指定しますか?

CustomHttpOperationHandlerFactoryも試してみましたが、役に立ちませんでした。

  public class CustomHttpOperationHandlerFactory: HttpOperationHandlerFactory
    {       
        protected override System.Collections.ObjectModel.Collection<HttpOperationHandler> OnCreateRequestHandlers(System.ServiceModel.Description.ServiceEndpoint endpoint, HttpOperationDescription operation)
        {
            var binding = (HttpBinding)endpoint.Binding;
            binding.MaxReceivedMessageSize = Int32.MaxValue;

            return base.OnCreateRequestHandlers(endpoint, operation);
        }
    }
4

4 に答える 4

4

maxReceivedMessageSizeは、使用しているバインディングで定義する必要のあるプロパティです。.Net 4のWCFでは簡略化された構成が導入されたため、何も構成しない場合は、既定値が使用されます。以下の例はwshttpBindingに有効です。使用したバインディングに従って修正し、servicemodel-bindingセクションのweb.config(IISホストサービスを使用していると想定)に登録します。

<wsHttpBinding>
    <binding name="CalculatorBinding" maxBufferPoolSize="2000000" maxReceivedMessageSize="2000000000" >
      <security mode="Transport" >
        <transport clientCredentialType="Windows" />
      </security>
      <readerQuotas maxDepth="2000000" maxStringContentLength="2000000"
      maxArrayLength="2000000"
      maxBytesPerRead="2000000"
      maxNameTableCharCount="2000000" />
    </binding>
  </wsHttpBinding>

HTHドミニク

于 2011-06-24T06:43:56.553 に答える
3

IISでホストしている場合は、ルートを定義する場所(私の場合はglobal.asax)で値を設定できます。バッファリング(デフォルト)に設定している場合は、と同じ値TransferModeに設定する必要もあります。MaxBufferSizeMaxReceivedMessageSize

protected void Application_Start()
{
   var config = new HttpConfiguration(); 
   config.MaxReceivedMessageSize = int.MaxValue;
   config.MaxBufferSize = int.MaxValue;
   RouteTable.Routes.MapServiceRoute<MyService>("api", config);
}
于 2011-10-24T19:22:02.140 に答える
3

これをプログラムで(HttpHostConfiguration.CreateでMapServiceRouteを使用して)実行しようとしている場合、実行方法は次のようになります。

IHttpHostConfigurationBuilder httpHostConfiguration = HttpHostConfiguration.Create(); //And add on whatever configuration details you would normally have

RouteTable.Routes.MapServiceRoute<MyService, NoMessageSizeLimitHostConfig>(serviceUri, httpHostConfiguration);  

NoMessageSizeLimitHostConfigは、次のようなHttpConfigurableServiceHostFactoryの拡張です。

public class NoMessageSizeLimitHostConfig : HttpConfigurableServiceHostFactory
{
    protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
    {
        var host = base.CreateServiceHost(serviceType, baseAddresses);  

        foreach (var endpoint in host.Description.Endpoints)
        {
            var binding = endpoint.Binding as HttpBinding;    

            if (binding != null)
            {
                binding.MaxReceivedMessageSize = Int32.MaxValue;
                binding.MaxBufferPoolSize = Int32.MaxValue;
                binding.MaxBufferSize = Int32.MaxValue;
                binding.TransferMode = TransferMode.Streamed;
            }
        }
        return host;
    }
}
于 2011-08-13T01:41:51.283 に答える
1

これはあなたがコードでそれを行うことができる方法です

var endpoint = ((HttpEndpoint)host.Description.Endpoints[0]);  //Assuming one endpoint
endpoint.TransferMode = TransferMode.Streamed;
endpoint.MaxReceivedMessageSize = 1024 * 1024 * 10;  // Allow files up to 10MB

標準ホストから派生した独自のカスタムホストを作成する場合は、オーバーロードしてHttpEndpointを構成できるメソッドがあります。

于 2011-06-24T21:14:14.210 に答える