相关疑难解决方法(0)

WCF GET URL长度限制问题:错误请求 - 无效的URL

我试图通过使用GET方法的jQuery AJAX调用来访问WCF服务.因此,有时URL的参数很长.

当参数变得如此冗长时,jQuery AJAX调用失败,并且什么都不返回.所以我提出了一个断点并把URL拿出去测试.当我在浏览器中尝试使用相同的URL时(我尝试过FireFox和Chrome),当URL长度过长时会返回以下内容.

错误请求 - 无效的网址

HTTP错误400.请求URL无效.

我也检查了长度限制.当URL中的字符数(编码格式)超过1011个字符(包括http://)时,我才会收到错误.

任何人都有相同的情况,并找到任何解决方案吗?是Windows限制还是可以通过编程方式通过任何设置进行管理?

我试过POST方法,但我不知道我无法使它工作.因为它需要一些web.config更改.

编辑

我测试过生成错误的URL

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
Run Code Online (Sandbox Code Playgroud)

未编码的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
Run Code Online (Sandbox Code Playgroud)

我的参数是Json对象的集合.我不认为任何字符会导致问题,因为,如果我只是将少数字母数字字符减少到小于限制,它就可以工作.

我正在使用Windows 8 Professional中的Visual Studio 2012 Premium运行我的应用程序,所以它是.NET 4.5和IIS Express随之而来.

进一步的研究

当我试图进一步调查时,这不是我已经提到的限制,即完整网址的长度.但是,每个参数的长度限制为260个字符.

所以,我不确定URL的总长度,但是每个参数(用"/"分隔)都有限制.我发布的上述URL的问题是电子邮件地址JSON参数长度为261个字符,如下所示.

[{"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"}]
Run Code Online (Sandbox Code Playgroud)

如果我从中删除1个字符,它就可以了.

是浏览器限制吗?操作系统限制?

更新:解决方案

当我进一步研究这个问题时,我找到了一个对我有用的解决方案.我在这里更新,因为它可能对遇到这个问题的其他人有用.

这是一个IIS设置

问题是因为,REST url中每个参数的默认字符限制是260,它在注册表中定义.

因此,您必须更新注册表以增加运行IIS Server/IIS Express的此大小限制.

以下是注册表的位置:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\HTTP\Parameters
Run Code Online (Sandbox Code Playgroud)

值名称是UrlSegmentMaxLength.如果不存在,请使用Type of创建一个REG_DWORD.并指定一个更高的值,value data例如十六进制的1000或十进制的4096.

这是一个http.sys设置.有关http.sys设置的更多信息:http://support.microsoft.com/kb/820129

确保重新启动服务器/计算机以应用注册表更改.就是这样.

browser ajax wcf jquery get

20
推荐指数
1
解决办法
2万
查看次数

标签 统计

ajax ×1

browser ×1

get ×1

jquery ×1

wcf ×1