[.net] WCF-메시지 크기 할당량을 늘리는 방법

데이터베이스에서 클라이언트로 1000 레코드를 반환하는 WCF 서비스가 있습니다. ASP.NET WCF 클라이언트가 있습니다 (WCF를 사용하기 위해 asp.net 웹 응용 프로그램 프로젝트에 서비스 참조를 추가했습니다).

클라이언트 응용 프로그램을 실행할 때 다음 메시지가 나타납니다.

수신 메시지의 최대 메시지 크기 할당량 (65536)을 초과했습니다. 할당량을 늘리려면 적절한 바인딩 요소에서 MaxReceivedMessageSize 속성을 사용하십시오.

어떤 도움? 메시지 크기 할당량을 늘리는 방법은 무엇입니까?



답변

App.config 또는 Web.config 파일 에서 메시지 크기 할당량을 늘리려면 다음과 같은 것이 필요 합니다.

<bindings>
    <basicHttpBinding>
        <binding name="basicHttp" allowCookies="true"
                 maxReceivedMessageSize="20000000"
                 maxBufferSize="20000000"
                 maxBufferPoolSize="20000000">
            <readerQuotas maxDepth="32"
                 maxArrayLength="200000000"
                 maxStringContentLength="200000000"/>
        </binding>
    </basicHttpBinding>
</bindings>

그리고 엔드 포인트 구성에서 바인딩 이름을 사용하십시오. 예 :

...
bindingConfiguration="basicHttp"
...

값의 정당성은 간단하며 대부분의 메시지를 수용 할 수있을만큼 충분히 큽니다. 필요에 따라 해당 번호를 조정할 수 있습니다. 낮은 기본값은 기본적으로 DOS 유형 공격을 방지하기위한 것입니다. 20000000으로 만들면 분산 DOS 공격이 효과적 일 수 있으며 기본 크기 인 64k는 요즘 대부분의 서버를 압도하는 많은 수의 클라이언트가 필요합니다.


답변

WCF 테스트 클라이언트를 사용하는 동안이 오류 메시지가 계속 표시되면 클라이언트에 별도의 MaxBufferSize 가 있기 때문입니다. 설정 입니다.

문제를 해결하려면

  1. 구성 파일을 마우스 오른쪽 버튼으로 클릭트리 맨 아래 노드를
  2. SvcConfigEditor로 편집을 선택하십시오.

MaxBufferSize를 포함하여 편집 가능한 설정 목록이 나타납니다.

참고 : 자동 생성 프록시 클라이언트는 기본적으로 MaxBufferSize를 65536으로 설정합니다.


답변

WCF 바인딩을 동적으로 작성하는 경우 사용할 코드는 다음과 같습니다.

BasicHttpBinding httpBinding = new BasicHttpBinding();
httpBinding.MaxReceivedMessageSize = Int32.MaxValue;
httpBinding.MaxBufferSize = Int32.MaxValue;
// Commented next statement since it is not required
// httpBinding.MaxBufferPoolSize = Int32.MaxValue;


답변

WCF 테스트 클라이언트 그 자체가 클라이언트의 설정을 가지고 있습니다.

테스트 클라이언트를 실행하고 맨 아래로 스크롤하십시오. 구성 파일 노드를 두 번 클릭하면 XML 표시가 나타납니다. 당신이 볼 수 있듯이 maxReceivedMessageSizeIS를65536 .

이를 편집하려면 구성 파일 트리 노드를 마우스 오른쪽 단추로 클릭하고 다음으로 편집을 선택하십시오. SvcConfigEditor . 편집기가 열리면 바인딩을 펼치고 자동으로 생성 된 바인딩을 두 번 클릭하십시오.

를 포함하여 여기에서 모든 속성을 편집 할 수 있습니다 maxReceivedMessageSize. 완료되면 파일-저장을 클릭 하십시오 .

마지막으로 WCF 테스트 클라이언트 창으로 돌아 오면 도구-옵션을 클릭하십시오 .

참고 : 서비스를 시작할 때 항상 구성 재생성을 선택 취소하십시오 .


답변

나는 쉬운 길을 찾았다

— webconfig 또는 app config 파일을 마우스 오른쪽 버튼으로 클릭하고 WCF 구성 편집을 클릭하고 선택 yore 서비스 및 오른쪽 표시 maxReciveMessageSize를 bingdigs해야합니다.


답변

다음과 같이 문제를 해결합니다 …

    <bindings>
  <netTcpBinding>
    <binding name="ECMSBindingConfig" closeTimeout="00:10:00" openTimeout="00:10:00"
      sendTimeout="00:10:00" maxBufferPoolSize="2147483647" maxBufferSize="2147483647"
      maxReceivedMessageSize="2147483647" portSharingEnabled="true">
      <readerQuotas maxArrayLength="2147483647" maxNameTableCharCount="2147483647"
          maxStringContentLength="2147483647" maxDepth="2147483647"
          maxBytesPerRead="2147483647" />
      <security mode="None" />
    </binding>
  </netTcpBinding>
</bindings>
<behaviors>
  <serviceBehaviors>
    <behavior name="ECMSServiceBehavior">
      <dataContractSerializer ignoreExtensionDataObject="true" maxItemsInObjectGraph="2147483647" />
      <serviceDebug includeExceptionDetailInFaults="true" />
      <serviceTimeouts transactionTimeout="00:10:00" />
      <serviceThrottling maxConcurrentCalls="200" maxConcurrentSessions="100"
        maxConcurrentInstances="100" />
    </behavior>
  </serviceBehaviors>
</behaviors>


답변

CalculateRoute ()를 사용하여 프로젝트의 Bing Maps WPF에서 문제를 해결했습니다. 필자의 경우 솔루션은 “customBinding”섹션의 “httpTransport”속성에서 maxReceivedMessageSize 및 maxReceivedMessageSize를 설정했습니다.

applications.config 파일 (예 : myApp.config)에서이 구성을 설정했습니다.

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_IGeocodeService" />
            <binding name="BasicHttpBinding_IRouteService" />
        </basicHttpBinding>
        <customBinding>
            <binding name="CustomBinding_IGeocodeService">
                <binaryMessageEncoding />
              <httpTransport manualAddressing="false" maxBufferPoolSize="524288"
                                maxReceivedMessageSize="2147483647" allowCookies="false" authenticationScheme="Anonymous"
                                bypassProxyOnLocal="false" decompressionEnabled="true" hostNameComparisonMode="StrongWildcard"
                                keepAliveEnabled="true" maxBufferSize="2147483647" proxyAuthenticationScheme="Anonymous"
                                realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"
                                useDefaultWebProxy="true" />
            </binding>
            <binding name="CustomBinding_IRouteService">
                <binaryMessageEncoding />
              <httpTransport manualAddressing="false" maxBufferPoolSize="524288"
                                maxReceivedMessageSize="2147483647" allowCookies="false" authenticationScheme="Anonymous"
                                bypassProxyOnLocal="false" decompressionEnabled="true" hostNameComparisonMode="StrongWildcard"
                                keepAliveEnabled="true" maxBufferSize="2147483647" proxyAuthenticationScheme="Anonymous"
                                realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"
                                useDefaultWebProxy="true" />
            </binding>
        </customBinding>
    </bindings>
    <client>
        <endpoint address="http://dev.virtualearth.net/webservices/v1/geocodeservice/GeocodeService.svc"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IGeocodeService"
            contract="BingServices.IGeocodeService" name="BasicHttpBinding_IGeocodeService" />
        <endpoint address="http://dev.virtualearth.net/webservices/v1/geocodeservice/GeocodeService.svc/binaryHttp"
            binding="customBinding" bindingConfiguration="CustomBinding_IGeocodeService"
            contract="BingServices.IGeocodeService" name="CustomBinding_IGeocodeService" />
        <endpoint address="http://dev.virtualearth.net/webservices/v1/routeservice/routeservice.svc"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IRouteService"
            contract="BingServices.IRouteService" name="BasicHttpBinding_IRouteService" />
        <endpoint address="http://dev.virtualearth.net/webservices/v1/routeservice/routeservice.svc/binaryHttp"
            binding="customBinding" bindingConfiguration="CustomBinding_IRouteService"
            contract="BingServices.IRouteService" name="CustomBinding_IRouteService" />
    </client>
</system.serviceModel>