I tried to access a WCF Service through jQuery AJAX call with GET method. So, sometimes the URL is lengthy with parameters.
When the parameters becomes so lengthy, jQuery AJAX Call fails, and returns nothing. So I put a break point and took the URL out to test. When I try the same URL in the browser (I tried FireFox and Chrome), it returns the following when the URL length is too long.
Bad Request - Invalid URL
HTTP Error 400. The request URL is invalid.
I checked the length limitation as well. When the number of characters in the URL (in encoded format) exceeds 1011 characters (including http://) only I get the error.
I tried POST method, but I don't know I could not make it work. Because it needs some web.config changes.
My Parameters are set of Json Objects. I don't think any of the characters cause the problem, because, if I just reduce few alpha numeric characters to less than the limit, it works.
I'm running my application in Visual Studio 2012 Premium in Windows 8 Professional, so it's .NET 4.5 and IIS Express Came with it.
Further Research
When I try to investigate this further, this is not the limitation I have already mentioned which is the length of full url. But, there is a limitation of length in each parameter which is 260 characters.
So, I'm not sure about URL total length, but each parameter (seperated by "/") has the limit. The problem with the above URL which I have posted is Email Address JSON parameter is 261 characters long, given below.
SOLUTION
I Found a solution which worked for me, when I research further on this.
There is an IIS Setting
The problem is because, the default character limit of each parameter in REST url is 260 which is defined in the registry.
So, you have to update the registry to increase this size limit where the IIS Server / IIS Express is running.
Following is the location of Registry:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\HTTP\Parameters
And the value name is UrlSegmentMaxLength
. If it is not there, create one with Type of REG_DWORD
. And specify a higher value for value data
such as 1000 in hexadecimal or 4096 in decimal.
Make sure, you restart the server/machine to apply the registry changes. And that's it.