2010-03-16 3 views
14

클라이언트에서 프로그래밍 방식으로 MaxReceivedMessageSize 속성을 더 높은 한계 ((400) Bad Request 오류로 인해)로 설정하려고합니다. 이 ... 내가 사용하고있는 코드입니다WCF 클라이언트를 사용할 때 프로그래밍 방식으로 MaxReceivedMessageSize를 설정하는 방법?

WCFServiceTestClient wcfClient = 
    new WCFServiceTestClient(new wsHttpBinding(), strServiceURL); 

내 서비스 URL은 Web.config의를 사용할 수 없습니다 따라서 동적이며.

//The following code doesnt seem to take effect 
((WSHttpBinding)wcfClient.ChannelFactory.Endpoint.Binding) 
     .MaxReceivedMessageSize = 2147483647; 

내가 뭘 잘못하고 있니?
도움을 주시면 감사하겠습니다.
감사 프랫

답변

20


는 클라이언트를 인스턴스화하기 전에 MaxReceivedMessageSize을 설정할 수 있도록 재 주문 전화를 시도? 예를 들면,

var binding = new wsHttpBinding(); 
binding.MaxReceivedMessageSize = Int32.MaxValue; 
var wcfClient = new WCFServiceTestClient(binding, strServiceURL); 

이 나 있지만, 당신의 400 오류 도움이되지 않을 수 있습니다.

8

내 WCF 서비스에서 유사한 문제가 있었다 나는 그것을 해결 : 그것은이 명확하지 비록,

CustomBinding binding = (CustomBinding)PDAServiceContractClient.CreateDefaultBinding(); 
      HttpTransportBindingElement httpBindingElement = new HttpTransportBindingElement(); 
      httpBindingElement.MaxBufferSize = Int32.MaxValue; 
      httpBindingElement.MaxReceivedMessageSize = Int32.MaxValue; 
      binding.Elements.Add(httpBindingElement); 

      string address = PDAServiceContractClient.EndpointAddress.Uri.ToString(); 
      m_proxy = new PDAServiceContractClient(binding, new EndpointAddress(address)); 
0

이 잘 작동합니다. 모든 기존 바인딩 속성을 유지하고 MaxReceivedMessageSize 만 조정합니다 (덧붙여 MaxBufferSize도 같은 크기로 증가합니다).

Dim oClient as WcfClient = New WcfClient 
CType(oClient.Endpoint.Binding, ServiceModel.BasicHttpBinding).MaxReceivedMessageSize = Int32.MaxValue 
관련 문제