Im using Web Client UploadString to send an Xml as a string to another server created by me. When invoking the UploadString I get a (500-Internal server Error). Im debugging the service that is supposably throwing the exception but I never get there! (there is also a log to prove it). Im using web client in the following way:
using(WebClient webclient = new WebClient())
{
webclient.Encoding = UTF8Encoding.UTF8;
webclient.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
webclient.UseDefaultCredentials = true;
webclient.UploadString(url, stringToUpload);
}
I know the following facts:
Is there a limitation to the size of the string Im sending? If so, What should I do to enable this send or is there another way to handle this situation? Furthermore, Why does the server throws 500 if it realy isn't an internal server error?
Thanks
Yes, there is a limitation for a request when it is sent to asp.net:
<configuration>
<system.web>
<httpRuntime maxRequestLength="1048576" />
</system.web>
</configuration>
(on iis7 it is:
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824" />
</requestFiltering>
</security>
</system.webServer>
)
Check your remote service to see if your request length is not too big. Pay also attention to the request timeout, which may cut your upload if it takes too long) There are solutions to sidestep this problem: chunking your request, or using frameworks that are able to handle it directly.
From the point of view of the server it is served as an internal error, but you could perhaps change the behavior by massaging the error into something else