Search code examples
c#web-serviceswsdlsoapuimaxreceivedmessagesize

MaxReceivedMessageSize Error when Calling Batch Service from Application but not from SoapUI


I have a very annoying issue when sending a request to a web service.

One of the parameters of the request message is Batch, which can be set to either Y or N. When I set this to N there is no issue, and I get a response containing details for a single order.

However, when I set Batch to Y, I see this error:

Additional information: The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.

To resolve this, I tried setting the MaxReceivedMessageSize before calling the service:

public Provider.GetMessageResponse GetOrders(bool acceptBatch)
{
    var httpBinding = new BasicHttpBinding();
    httpBinding.MaxReceivedMessageSize = 2097152;
    httpBinding.MaxBufferSize = 2097152;

    var request = BuildRequest(acceptBatch);
    var client = new Provider.PullServiceClient();
    var response = client.PullGetMessage(SecurityToken, request);
    return response;
}

However, I still see the error message (even though I can see that httpBinding.MaxReceivedMessageSize has indeed been increased after running that code), and the service (not hosted by me) tells me that the messages have been collected (which does make sense, as it seems as if the messages are only being blocked once they reach my system).

Furthermore, when I execute the exact same request from the SoapUI application using xml, I do receive a batch response without any issues, and I can see a long list of all available orders.

So does this MaxReceivedMessageSize property only apply to my application and not the whole system? If that is the case, why does the code above not resolve this?


Solution

  • After looking at what overloaded constructors there were for Provider.PullServiceClient, I managed to resolve this issue by including the following parameters:

    var binding = new BasicHttpBinding() { MaxReceivedMessageSize = 2097152, MaxBufferSize = 2097152 };
    var endpoint = new EndpointAddress("http://test.providerporal.co.za/testservice/pullservice.svc");
    
    var client = new Provider.PullServiceClient(binding, endpoint);
    

    So I guess this limit is somehow related to my application, but the HttpBinding needed to be bound to request itself. Hopefully this helps someone else.