BinaryMisfit
BinaryMisfit

Reputation: 30589

How to increase the POST size for an ASMX web service?

Background

I am developing an ASP.Net server side control that needs to talk to an ASMX web service. The server side control uses a WebClient object to talk to the web service, since it needs to be reused often in various application, and to make it easier on the developers, they are not required to create a service reference to the web service.

Implementation

During the use of the control, it is requires the sending of a serialised object to the web service. The object is serialised using the XmlSerializer and the resulting XML string is then compressed using the chilkat compression library. The web service call for the control looks as follows:

webClient.UploadStringAsync(new Uri(serviceHost + serviceMethod), "POST", sendData)

The content of sendData (string) is compressedResponse={CompressedData}.

The web service has a method defined as follows to receive the data and then decompress the string value using the chilkat library before de-serialising the object using the XmlSerializer.

public void SaveResponse(string compressedResponse)

The communication between the control and the service is working. Initially there were no settings or binding defined in the web.config for any of the above. After initial searching I did add

<httpRuntime maxRequestLength="20480"/>

to both the client and server web.config files. This has made no difference.

Problem

Compressed or uncompressed the data being posted to the web service in the sendData variable is to big for a normal POST request, and is corrupted. This is confirmed when checking the last few characters of the string before and after it being posted to the server in compressed format, and uncompressed, the Xml document is missing the last root tag when checking in the debugger. The string can't be decompressed and therefore the service call fails every time.

How do I increase the POST size for the WebClient request to ensure that the full string is received by the server?

I have looked at the various option on Google, but none are giving me a good enough sample of where to make the changes, or samples of what the changes need to look like. I am completely lost as to whether the change needs to be made on the server or the consuming website, and since there are no binding defined for this, how to create a binding in the web.config for an ASMX HTTP service call.

Upvotes: 8

Views: 18075

Answers (2)

BinaryMisfit
BinaryMisfit

Reputation: 30589

There seems to be no way to change the POST size for a ASMX Web Service when only HttpPost is enabled.

The solution in the end was to switch the service to running HttpSoap and create a service reference to the assembly containing the control. Once done the binding is created using code in the control once the endpoint is set via a property.

Upvotes: 2

VinayC
VinayC

Reputation: 49245

I believe you must be hitting ASP.NET max request length limit. That you can modify via config file such as:

<system.web>
  <httpRuntime executionTimeout="240" maxRequestLength="20480" />
</system.web>

maxRequestLength value is in KB, so above setting would allow 20 MB. You can also apply the setting only to selected URLs using location tag e.g.

<location path="yourservice.asmx">
    <system.web>
        <httpRuntime executionTimeout="240" maxRequestLength="20480" />
    </system.web>
</location>

Upvotes: 6

Related Questions