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 설정이 별도이기 때문입니다.
문제 해결 방법:
- 트리 맨 아래에 있는 Config File 노드를 마우스 오른쪽 버튼으로 클릭합니다.
- 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 테스트 클라이언트에는 자체 클라이언트 구성이 있습니다.
테스트 클라이언트를 실행하고 맨 아래로 스크롤합니다.Config File 노드를 두 번 클릭하면 XML 표현이 표시됩니다. 바와 maxReceivedMessageSize
이라65536
.
를 마우스 오른쪽 버튼으로 With 편집구파일성트노마드오우버다클른로선니합택편릭대상을집고를 합니다.SvcConfigEditor
편집기가 열리면 바인딩을 확장하고 자동으로 생성된 바인딩을 두 번 클릭합니다.
다을포함모속편수집있다습니할성을든을 포함한 모든 할 수 maxReceivedMessageSize
완료되면 [파일] - [저장]을 누릅니다.
마지막으로 WCF Test Client 창으로 돌아가면 [도구] - [옵션]을 클릭합니다.
참고: 서비스를 시작할 때 항상 구성 다시 생성을 선택 취소합니다.
나는 쉬운 방법을 찾았습니다.
웹 구성 또는 앱 구성 파일을 마우스 오른쪽 버튼으로 클릭하고 WCF 구성 편집을 클릭하면 bingdigsans selectore service 및 show maxReciveMessageSize가 큰 숫자를 제공합니다. ---
나는 그 문제를 다음과 같이 해결합니다.
<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>
제 경험에서 고려해야 할 또 다른 중요한 것은..
app-domain(즉, Application Pool)이 재활용될 때까지 풀의 버퍼는 절대 해제되지 않으므로 maxBufferPoolSize를 최대화하지 않는 것이 좋습니다.
트래픽이 많은 기간 동안 많은 메모리가 사용되고 해제되지 않을 수 있습니다.
자세한 내용은 여기:
- https://stackoverflow.com/a/19953113/496676
- http://andriybuday.com/2011/08/wcf-configuration-caused-memory-leaks.html
HTTP의 경우:
<bindings>
<basicHttpBinding>
<binding name="basicHttp" allowCookies="true"
maxReceivedMessageSize="20000000"
maxBufferSize="20000000"
maxBufferPoolSize="20000000">
<readerQuotas maxDepth="200"
maxArrayLength="200000000"
maxBytesPerRead="4096"
maxStringContentLength="200000000"
maxNameTableCharCount="16384"/>
</binding>
</basicHttpBinding>
</bindings>
TCP의 경우:
<bindings>
<netTcpBinding>
<binding name="tcpBinding"
maxReceivedMessageSize="20000000"
maxBufferSize="20000000"
maxBufferPoolSize="20000000">
<readerQuotas maxDepth="200"
maxArrayLength="200000000"
maxStringContentLength="200000000"
maxBytesPerRead="4096"
maxNameTableCharCount="16384"/>
</binding>
</netTcpBinding>
</bindings>
중요:
연결된 개체가 많은 복잡한 개체(예: 트리 데이터 구조, 개체가 많은 목록...)를 전달하려고 하면 할당량을 늘린 방법에 관계없이 통신이 실패합니다.이러한 경우 포함하는 개체 수를 늘려야 합니다.
<behaviors>
<serviceBehaviors>
<behavior name="NewBehavior">
...
<dataContractSerializer maxItemsInObjectGraph="2147483646"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="wsHttpBinding_Username" maxReceivedMessageSize="20000000" maxBufferPoolSize="20000000">
<security mode="TransportWithMessageCredential">
<message clientCredentialType="UserName" establishSecurityContext="false"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint
binding="wsHttpBinding"
bindingConfiguration="wsHttpBinding_Username"
contract="Exchange.Exweb.ExchangeServices.ExchangeServicesGenericProxy.ExchangeServicesType"
name="ServicesFacadeEndpoint" />
</client>
제가 해야 할 일은 다음과 같습니다.maxReceivedMessageSize="2147483647"
클라이언트 app.config로 이동합니다.서버가 그대로 유지되었습니다.
실행 진입점의 app.config가 고려된다는 것을 잊지 마십시오. 클래스 라이브러리 프로젝트에서 웹 서비스 호출을 관리하는 것이 아닙니다.
예를 들어 장치 테스트를 실행하는 동안 오류가 발생하면 테스트 프로젝트에서 적절한 구성을 설정해야 합니다.
web.config에서 이 설정을 사용할 때 이 오류가 발생했습니다.
System.ServiceModel.ServiceActivationException
나는 다음과 같은 설정을 합니다.
<service name="idst.Controllers.wcf.Service_Talks">
<endpoint address="" behaviorConfiguration="idst.Controllers.wcf.Service_TalksAspNetAjaxBehavior"
binding="webHttpBinding" contract="idst.Controllers.wcf.Service_Talks" />
</service>
<service name="idst.Controllers.wcf.Service_Project">
<endpoint address="" behaviorConfiguration="idst.Controllers.wcf.Service_ProjectAspNetAjaxBehavior"
binding="basicHttpBinding" bindingConfiguration="" bindingName="largBasicHttp"
contract="idst.Controllers.wcf.Service_Project" />
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="largBasicHttp" allowCookies="true"
maxReceivedMessageSize="20000000"
maxBufferSize="20000000"
maxBufferPoolSize="20000000">
<readerQuotas maxDepth="32"
maxArrayLength="200000000"
maxStringContentLength="200000000"/>
</binding>
</basicHttpBinding>
언급URL : https://stackoverflow.com/questions/884235/wcf-how-to-increase-message-size-quota
'programing' 카테고리의 다른 글
인스턴스 참조를 사용하여 멤버 "에 액세스할 수 없습니다. (0) | 2023.05.08 |
---|---|
프로그래머는 SSIS를 사용해야 하며, 그렇다면 그 이유는 무엇입니까? (0) | 2023.05.08 |
모든 테이블(PostgreSQL)에서 특정 값을 검색하는 방법은 무엇입니까? (0) | 2023.05.08 |
PostgreSQL의 함수 내부에서 SELECT 결과를 반환하는 방법은 무엇입니까? (0) | 2023.05.08 |
WPF 데이터 그리드가 선택한 행 스타일 (0) | 2023.05.08 |