WCF GET URL Length Limit Issue: Bad Request - Invalid URL WCF GET URL Length Limit Issue: Bad Request - Invalid URL ajax ajax

WCF GET URL Length Limit Issue: Bad Request - Invalid URL


Reposting the update as Answer, since some of you might jump directly into the Answers section.

I Found a solution which worked for me, when I research further on this. I'm updating here since it might be useful for others who come across this question.

This 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\ParametersAnd 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.

This is a http.sys setting. More about http.sys settings : http://support.microsoft.com/kb/820129

Make sure, you restart the server/machine to apply the registry changes. And that's it.


A couple things to think about:

1) You shouldn't use a GET to do saving of data, use POST when possible. The main reason has to do with security. Using GET opens you up to more potential CSRF attacks. Keep in mind that POST is not immune to CSRF, but using it reduces the vulnerability a bit.

2) Looking at the URL, the commas look out of place to me and could be why you are getting invalid URL errors.

3) What version of IIS are you running under? This may determine what you have to do to increase the max URL Length.

For IIS7 you could add to System.Web in the config file:

<httpRuntime maxUrlLength="2000" />

EDIT:

You should try changing it to a POST again as it won't try mapping it to a file system.

From MSDN the windows api only allows 260.

In the Windows API (with some exceptions discussed in the following paragraphs), the maximum length for a path is MAX_PATH, which is defined as 260 characters. A local path is structured in the following order: drive letter, colon, backslash, name components separated by backslashes, and a terminating null character. For example, the maximum path on drive D is "D:\some 256-character path string" where "" represents the invisible terminating null character for the current system codepage. (The characters < > are used here for visual clarity and cannot be part of a valid path string.)


By editing the regestry it solved my problem of the bad Request 400, but stil doesn't work for me until i added,

<httpRuntime maxUrlLength="6144" relaxedUrlToFileSystemMapping="true" />

for note i tryed to add this configuration before editing my regestry but it didn't work so i guess after editing the Regestry and with this config i set it up well.may it help some one else.