2011-12-05 3 views
16

내가 처리하려고하는이 미친 문제가 있습니다. 엄청난 양의 데이터를 가져올 때 클라이언트 .config 파일의 할당량을 늘려야하지만 클라이언트가 WCF 서버에 거대한 데이터를 보내는 경우 어떻게해야할까요?들어오는 메시지의 최대 메시지 크기 할당량 (65536) .... 할당량을 늘리려면 MaxReceivedMessageSize 속성을 사용하십시오.

작은 크기의 입력 매개 변수를 보내면 정상적으로 작동합니다. 불행히도 입력이 커지면 분해됩니다.

디버거는 말한다 :

잘못된 요청, 400;

추적 파일에는 다음과 같습니다 수신 메시지 (65536)에 대한

최대 메시지 크기 할당량 초과했습니다. 할당량을 늘리려면 적절한 바인딩 요소에 MaxReceivedMessageSize 속성을 사용합니다.

서버 쪽에서 데이터를 가져 오는이 할당량을 늘릴 수있는 방법이 있습니까? 그렇다면 어떻게?

여기 내 샘플 설정 관련이 부품 : 여기

<bindings> 
    <basicHttpBinding> 
    <binding name="MyBasicHttpBinding" 
     closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" 
     sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" 
     hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" 
     maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" 
     messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" 
     useDefaultWebProxy="true"> 
     <readerQuotas maxDepth="64" maxStringContentLength="2147483647" maxArrayLength="2147483647" 
      maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> 
     <security mode="None"> 
     <transport clientCredentialType="None" proxyCredentialType="None" 
      realm="" /> 
     <message clientCredentialType="UserName" algorithmSuite="Default" /> 
     </security> 
    </binding> 

    </basicHttpBinding> 
</bindings> 

<services> 
    <service name="MyWcfService"> 
    <endpoint address="http://myservice..." 
     binding="basicHttpBinding" bindingConfiguration="MyBasicHttpBinding" 
     name="MyBasicHttpBinding" contract="IMyContract" /> 
    </service> 
</services> 

및 내 클라이언트 측 코드입니다 (나는 동적으로 생성) :

 var binding = new BasicHttpBinding(); 
     binding.MaxBufferPoolSize = 2147483647; 
     binding.MaxBufferSize = 2147483647; 
     binding.MaxReceivedMessageSize = 2147483647; 
     binding.ReaderQuotas.MaxStringContentLength = 2147483647; 
     binding.ReaderQuotas.MaxArrayLength = 2147483647; 
     binding.ReaderQuotas.MaxDepth = 2147483647; 
     binding.ReaderQuotas.MaxBytesPerRead = 2147483647; 


     var address = new EndpointAddress("http://mylocalservice.."); 

     ChannelFactory<IMyContract> factory = new ChannelFactory<IMyContract>(binding, address); 

     foreach (OperationDescription op in factory.Endpoint.Contract.Operations) 
     { 
      DataContractSerializerOperationBehavior dataContractBehavior = 
         op.Behaviors.Find<DataContractSerializerOperationBehavior>() 
         as DataContractSerializerOperationBehavior; 
      if (dataContractBehavior != null) 
      { 
       dataContractBehavior.MaxItemsInObjectGraph = 2147483646; 
      } 
     } 
     public IMyContract MyClientObject = factory.CreateChannel(); 
+0

난 [여기] 한 단계에서 문제를 해결 [1] [1]에 http : // 유래.com/questions/7476853/wcf-error-maximum-of-so-serialize 또는 deserialized-in-an/8656402 # 8656402 – Ram

+1

클라이언트 측 코드에서 코드를 통해 readerquotas를 설정합니다. 그래서 아래에 그것들을 설정하는 접근법이 있습니다 : XmlDictionaryReaderQuotas myReaderQuotas = new XmlDictionaryReaderQuotas(); myReaderQuotas.MaxStringContentLength = 2147483647; myReaderQuotas.MaxArrayLength = 2147483647; myReaderQuotas.MaxBytesPerRead = 2147483647; myReaderQuotas.MaxDepth = 64; myReaderQuotas.MaxNameTableCharCount = 2147483647; binding.GetType(). GetProperty ("ReaderQuotas"). SetValue (binding, myReaderQuotas, null); – Rajesh

답변

36

당신은을 통해 서비스에 MaxReceivedMessageSize 속성을 설정할 수 있습니다 서비스의 설정 파일.

클라이언트의 MaxReceivedMessageSize 설정은 클라이언트가받은 메시지에만 영향을줍니다.; 서비스가 수신 한 메시지에는 영향을 미치지 않습니다. 따라서 서비스가 큰 메시지를 수신 할 수있게하려면 서비스의 구성 파일을 설정해야합니다.

샘플 서비스 구성

<system.serviceModel> 
    <bindings> 
    <wsHttpBinding> 
     <binding name="MyBinding" maxReceivedMessageSize="2147483647" /> 
    </wsHttpBinding> 
    </bindings> 
    <services> 
    <service name="MyService"> 
     <endpoint address="http://myservice" binding="wsHttpBinding" 
       bindingConfiguration="MyBinding" contract="IMyServiceContract" /> 
    </service> 
    </services> 
</system.serviceModel> 

위의 매우 벗었 설정 파일이지만, 관련 부분을 보여줍니다. 중요한 부분은 바인딩을 정의하고 이름을 지정하고 기본값과 다른 값을 명시 적으로 설정하고 해당 이름을 끝점 요소의 bindingConfiguration 특성에 사용하는 것입니다.

+0

문제는 서버 쪽에서 바인딩 구성이 보이지 않는다는 것입니다. 거기에 몇 가지 기본 바인딩이나 뭔가가 무엇입니까? 어떻게 무시할 수 있습니까? –

+1

예, 있습니다. 설정 파일에 특정 바인딩 섹션이 없으며 bindingConfiguration 속성을 통해 ''요소에서 참조되지 않으면 바인딩의 기본값 (MaxReceivedMessageSize 속성의 경우 65536)이 사용됩니다. 따라서 적절한 ''섹션을 설정에 추가해야합니다. – Tim

+0

거기에 서버 측 바인딩 및/또는 끝점 구성의 모든 종류의 예가 있습니까? 나는 그 시점에서 이미 붙어 있습니다. –

5

이 문제는 아래 추가 바인딩 노드를 구성 파일의 바인딩 섹션에 추가하여 해결할 수 있습니다.

<basicHttpBinding> 
    <binding maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"> 
    <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" 
     maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> 
    </binding> 
</basicHttpBinding> 
+3

Welcome to StackOverflow. OP는 자신의 설정에 매우 유사한 코드를 가지고 있습니다. 당신의 대답은 그들이 가지고있는 것보다 어떤면에서 더 낫습니까? 응답을 향상시키기 위해 이전에하지 않은 대답을 설명합니다. – carlosfigueira

6

문제점이 wcf 테스트 클라이언트에서 발생했습니다. 어떤 이유로 인해 maxReceivedMessageSize가 증가한 클라이언트 구성을 생성하지 않습니다. 내 수정은 "Config 파일"-> "SvcConfigEditor로 편집"-> 바인딩 -> maxReceivedMessageSize를 마우스 오른쪽 버튼으로 클릭하는 것입니다.

+0

대부분의 대답은 서버에서 이러한 설정을 지정하는 방법을 보여줍니다. 하지만 여전히 오류가 발생했다면 언급 한대로 클라이언트에서이 설정을 구성해야합니다. 내 경우에는 은 먼저 웹 서비스를 소비하는 응용 프로그램의의 app.config이처럼 보였다 : <은 BasicHttpBinding> <바인딩 이름 = "BasicHttpBinding_ICGSIncomingSOAPCalls"/> <바인딩 이름 = "BasicHttpBinding_MyICGSIncomingSOAPCalls을"/> I는 다음과 같이 수정 (참조 2 부) : – mihai71

+0

... 제 2 부 : <은 BasicHttpBinding> <바인딩 이름 = "BasicHttpBinding_ICGSIncomingSOAPCalls"maxReceivedMessageSize = "10485760"maxBufferPoolSize = "10485760"가 MaxBufferSize = " 10485760 "/> <바인딩 이름 = "BasicHttpBinding_MyICGSIncomingSOAPCalls"maxReceivedMessageSize = "10485760"maxBufferPoolSize = "10485760"해당 MaxBufferSize = "10485760"/> 하고 확인했다. – mihai71

관련 문제