8

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.

BinaryMisfit
  • 29,219
  • 2
  • 37
  • 44
  • what leads you to believe that the string is too long? Just the fact that it can't be uncompressed? What's it look like in Fiddler? – John Saunders Jan 22 '11 at 05:18
  • @John I updated the question with the info. Doing a basic check on the compressed string by copying the last few characters before the post and validating it against the posted string. Also sending the uncompressed Xml document shows that the final root tag is missing, and it is cut off midway through when checking in the debugger. – BinaryMisfit Jan 22 '11 at 05:43

2 Answers2

6

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>
VinayC
  • 47,395
  • 5
  • 59
  • 72
  • I should have added to the question that I have already set this both for the client `web.config` and server `web.config`. I have updated the question to reflect this. +1 however for the detailed answer. – BinaryMisfit Jan 20 '11 at 08:17
  • @Diago, do you get any particular error? Can you share that details? – VinayC Jan 20 '11 at 08:21
  • @Diago, I am also curious as to how you are converting compressed data (presumably in byte array format) into a string. You need to apply reverse conversion after the receipt. Base64 would be a good candidate here for encoding compressed data to string. – VinayC Jan 20 '11 at 08:25
  • No specific error even after adding a try catch. The compression and decompression is done using the chilkat library and the string conversions are correct. The library for sending and receving the data works fine when recieving the data, and it uses the same methods for sending. The major difference is in the past individual values where being sent to the service, where now it recieves a complete object. If I can't find a solution to this I may be forced to go back to the old method. – BinaryMisfit Jan 20 '11 at 08:32
  • For reference the code to decompress the string is `decodedString = gzipEngine.InflateStringENC(compressedData, "windows-1252", "base64")` – BinaryMisfit Jan 20 '11 at 08:36
2

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.

BinaryMisfit
  • 29,219
  • 2
  • 37
  • 44