2010-03-16 28 views
14

Quiero establecer la propiedad MaxReceivedMessageSize en algún límite superior (debido a (400) Error de solicitud incorrecta) en mi cliente programáticamente. Este es el código que estoy utilizando ...¿Cómo se configura MaxReceivedMessageSize programáticamente cuando se utiliza un WCF Client?

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

Mi URL del servicio es dinámico y por lo tanto no se puede utilizar el web.config.

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

¿Qué estoy haciendo mal?
Se agradece cualquier ayuda.
Gracias
Pratt

Respuesta

20

¿Usted ha intentado volver a ordenar las llamadas de modo que se establece la MaxReceivedMessageSize antes de instanciar el cliente? por ejemplo,

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

Esto puede o no puede ayudar a su error 400.

8

tuve problemas similares en mi WCF-servicio y lo resolví con:

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

Esto funciona bien, a pesar de que no es tan obvio. Conserva todas las propiedades de enlace existentes y solo ajusta el MaxReceivedMessageSize (que, por cierto, también aumenta MaxBufferSize con el mismo tamaño).

Dim oClient as WcfClient = New WcfClient 
CType(oClient.Endpoint.Binding, ServiceModel.BasicHttpBinding).MaxReceivedMessageSize = Int32.MaxValue 
Cuestiones relacionadas