WCF GET网址长度上限问题:错误的请求 - 无效的网址 [英] WCF GET URL Length Limit Issue: Bad Request - Invalid URL

查看:264
本文介绍了WCF GET网址长度上限问题:错误的请求 - 无效的网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过jQuery的AJAX调用访问WCF服务与GET方法。所以,有时候URL是漫长与参数。

在参数变得如此漫长,jQuery的AJAX调用失败,并且没有返回。所以我把一个破发点,并采取了网址了测试。当我尝试在浏览器中相同的URL(我试过Firefox和Chrome),它返回时,URL长度太长以下。


  

错误的请求 - 无效的网址


  
  

HTTP错误400请求的URL是无效的。


我查了长度限制为好。当人物在URL中号(EN codeD格式)超过1011个字符(包括http://)只有我得到的错误

任何人有同样的情况,发现任何解决这个?它是Windows的限制还是可以通过任何设置进行管理编程?

我试过POST方法,但我不知道我不能使它工作。因为它需要一些web.config中的变化。

修改

该网址我已经测试到生成错误

<$p$p><$c$c>http://localhost:64973/Member.svc/SaveMemberWithDetail/%7B%22ID%22%7C%222%22,%22TypeID%22%7C%222%22,%22Title%22%7C%22Mr.%22,%22FirstName%22%7C%22Firnas%22,%22MiddleName%22%7C%22%22,%22LastName%22%7C%22Aliyar%22,%22Gender%22%7C%221%22,%22DateOfBirth%22%7C%222000-01-01%22,%22Nationality%22%7C%22Sri%20Lankan%22%7D/%5B%7B%22AddressLine1%22%7C%22Changed%20Address%20Line1%22,%22AddressLine2%22%7C%22Colombo%22,%22City%22%7C%22Colombo%2010%22,%22State%22%7C%22WP%22,%22Post$c$c%22%7C%2201000%22,%22CountryID%22%7C%221%22,%22ID%22%7C%227%22,%22TypeID%22%7C%221%22%7D%5D/%5B%7B%22Telephone%22%7C%22015154645%22,%22TypeID%22%7C%221%22%7D%5D/%5B%7B%22EmailAddress%22%7C%22gen1@dfs%22,%22ID%22%7C%2226%22,%22TypeID%22%7C%221%22%7D,%7B%22EmailAddress%22%7C%22gen2@jfasd%22,%22ID%22%7C%2227%22,%22TypeID%22%7C%221%22%7D,%7B%22EmailAddress%22%7C%22g1@e.cm%22,%22ID%22%7C%2228%22,%22TypeID%22%7C%221%22%7D,%7B%22EmailAddress%22%7C%22g2@gogle.com%22,%22ID%22%7C%2229%22,%22TypeID%22%7C%221%22%7D,%7B%22EmailAddress%22%7C%22g@go.com%22,%22ID%22%7C%2229%22,%22TypeID%22%7C%221%22%7D%5D/%7B%7D/481

Unen codeD URL的版本:

<$p$p><$c$c>http://localhost:64973/Member.svc/SaveMemberWithDetail/{\"ID\"|\"2\",\"TypeID\"|\"2\",\"Title\"|\"Mr.\",\"FirstName\"|\"Firnas\",\"MiddleName\"|\"\",\"LastName\"|\"Aliyar\",\"Gender\"|\"1\",\"DateOfBirth\"|\"2000-01-01\",\"Nationality\"|\"Sri斯里兰卡} / [{AddressLine1|更改地址行1,AddressLine2|科伦坡,城市|科伦坡10\",\"State\"|\"WP\",\"Post$c$c\"|\"01000\",\"CountryID\"|\"1\",\"ID\"|\"7\",\"TypeID\"|\"1\"}]/[{\"Telephone\"|\"015154645\",\"TypeID\"|\"1\"}]/[{\"EmailAddress\"|\"gen1@dfs\",\"ID\"|\"26\",\"TypeID\"|\"1\"},{\"EmailAddress\"|\"gen2@jfasd\",\"ID\"|\"27\",\"TypeID\"|\"1\"},{\"EmailAddress\"|\"g1@e.cm\",\"ID\"|\"28\",\"TypeID\"|\"1\"},{\"EmailAddress\"|\"g2@gogle.com\",\"ID\"|\"29\",\"TypeID\"|\"1\"},{\"EmailAddress\"|\"g@go.com\",\"ID\"|\"29\",\"TypeID\"|\"1\"}]/{}/481

我的参数设置JSON对象的。我不认为任何字符导致问题,因为,如果我只是减少一些字母数字字符不到极限,它的工作原理。

我跑我在Visual Studio 2012 premium应用程序在Windows 8专业版,所以它的.NET 4.5和IIS防爆preSS与它来了。

进一步研究

当我尝试进一步调查,这是不是我已经提到的局限性这是完整的URL的长度。但是,有长度在260个字符的每个参数的限制。

所以,我不知道URL总长度,但每个参数(由分隔/)有限制。与我已经发布了上述网址的问题是邮箱地址JSON参数是261个字符长,下面给出。

<$p$p><$c$c>[{\"EmailAddress\"|\"gen1@dfs\",\"ID\"|\"26\",\"TypeID\"|\"1\"},{\"EmailAddress\"|\"gen2@jfasd\",\"ID\"|\"27\",\"TypeID\"|\"1\"},{\"EmailAddress\"|\"g1@e.cm\",\"ID\"|\"28\",\"TypeID\"|\"1\"},{\"EmailAddress\"|\"g2@gogle.com\",\"ID\"|\"29\",\"TypeID\"|\"1\"},{\"EmailAddress\"|\"g@go.com\",\"ID\"|\"29\",\"TypeID\"|\"1\"}]

如果我删除这1个字符,它的工作原理。

它是浏览器的限制?操作系统限制?

更新:SOLUTION

我发现这工作对我来说,当我进一步研究了一个解决方案。我更新在这里,因为它可能是为别人谁遇到这个问题非常有用。

这是一个IIS设置

问题是因为在REST URL每个参数的默认字符限制为260这是在注册表中定义的。

所以,你必须更新注册表以提高那里的IIS服务器/ IIS防爆preSS运行这个大小限制。

以下是注册表的位置:

  HKEY_LOCAL_MACHINE \\系统\\ CurrentControlSet \\服务\\ HTTP \\参数

和值的名称是 UrlSegmentMaxLength 。如果它不存在,创建一个以 REG_DWORD 的类型。并指定一个较高的值值数据如1000十六进制或4096十进制。

这是一个HTTP.SYS设​​置。更多关于HTTP.SYS设​​置: http://support.microsoft.com/kb/820129

确认,重新启动服务器/计算机应用注册表更改。
就是这样。


解决方案

转贴更新为答案,因为有些人可能直接跳入答案部分。

我发现这工作对我来说,当我进一步研究了一个解决方案。我更新在这里,因为它可能是为别人谁遇到这个问题非常有用。

这是一个IIS设置

问题是因为在REST URL每个参数的默认字符限制为260这是在注册表中定义的。

所以,你必须更新注册表以提高那里的IIS服务器/ IIS防爆preSS运行这个大小限制。

以下是注册表的位置:

HKEY_LOCAL_MACHINE \\系统\\ CurrentControlSet \\服务\\ HTTP \\参数
和值名称是UrlSegmentMaxLength。如果它不存在,创建一个REG_DWORD与类型。并指定例如以十六进制1000或4096在十进制值数据更高的值。

这是一个HTTP.SYS设​​置。更多关于HTTP.SYS设​​置: http://support.microsoft.com/kb/820129

确认,重新启动服务器/计算机应用注册表更改。就是这样。

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.

Anyone has the same situation and found any solution to this? Is it Windows Limitation or Can it be managed through any settings programmatically?

I tried POST method, but I don't know I could not make it work. Because it needs some web.config changes.

EDIT

The URL I have Tested to Generate the Error

http://localhost:64973/Member.svc/SaveMemberWithDetail/%7B%22ID%22%7C%222%22,%22TypeID%22%7C%222%22,%22Title%22%7C%22Mr.%22,%22FirstName%22%7C%22Firnas%22,%22MiddleName%22%7C%22%22,%22LastName%22%7C%22Aliyar%22,%22Gender%22%7C%221%22,%22DateOfBirth%22%7C%222000-01-01%22,%22Nationality%22%7C%22Sri%20Lankan%22%7D/%5B%7B%22AddressLine1%22%7C%22Changed%20Address%20Line1%22,%22AddressLine2%22%7C%22Colombo%22,%22City%22%7C%22Colombo%2010%22,%22State%22%7C%22WP%22,%22PostCode%22%7C%2201000%22,%22CountryID%22%7C%221%22,%22ID%22%7C%227%22,%22TypeID%22%7C%221%22%7D%5D/%5B%7B%22Telephone%22%7C%22015154645%22,%22TypeID%22%7C%221%22%7D%5D/%5B%7B%22EmailAddress%22%7C%22gen1@dfs%22,%22ID%22%7C%2226%22,%22TypeID%22%7C%221%22%7D,%7B%22EmailAddress%22%7C%22gen2@jfasd%22,%22ID%22%7C%2227%22,%22TypeID%22%7C%221%22%7D,%7B%22EmailAddress%22%7C%22g1@e.cm%22,%22ID%22%7C%2228%22,%22TypeID%22%7C%221%22%7D,%7B%22EmailAddress%22%7C%22g2@gogle.com%22,%22ID%22%7C%2229%22,%22TypeID%22%7C%221%22%7D,%7B%22EmailAddress%22%7C%22g@go.com%22,%22ID%22%7C%2229%22,%22TypeID%22%7C%221%22%7D%5D/%7B%7D/481

Unencoded version of URL:

http://localhost:64973/Member.svc/SaveMemberWithDetail/{"ID"|"2","TypeID"|"2","Title"|"Mr.","FirstName"|"Firnas","MiddleName"|"","LastName"|"Aliyar","Gender"|"1","DateOfBirth"|"2000-01-01","Nationality"|"Sri Lankan"}/[{"AddressLine1"|"Changed Address Line1","AddressLine2"|"Colombo","City"|"Colombo 10","State"|"WP","PostCode"|"01000","CountryID"|"1","ID"|"7","TypeID"|"1"}]/[{"Telephone"|"015154645","TypeID"|"1"}]/[{"EmailAddress"|"gen1@dfs","ID"|"26","TypeID"|"1"},{"EmailAddress"|"gen2@jfasd","ID"|"27","TypeID"|"1"},{"EmailAddress"|"g1@e.cm","ID"|"28","TypeID"|"1"},{"EmailAddress"|"g2@gogle.com","ID"|"29","TypeID"|"1"},{"EmailAddress"|"g@go.com","ID"|"29","TypeID"|"1"}]/{}/481

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.

[{"EmailAddress"|"gen1@dfs","ID"|"26","TypeID"|"1"},{"EmailAddress"|"gen2@jfasd","ID"|"27","TypeID"|"1"},{"EmailAddress"|"g1@e.cm","ID"|"28","TypeID"|"1"},{"EmailAddress"|"g2@gogle.com","ID"|"29","TypeID"|"1"},{"EmailAddress"|"g@go.com","ID"|"29","TypeID"|"1"}]

If I delete 1 character from this, it works.

Is it Browser Limitation? OS Limitation?

UPDATE: SOLUTION

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

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.

解决方案

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

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.

这篇关于WCF GET网址长度上限问题:错误的请求 - 无效的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆