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

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

问题描述

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

I tried to access a WCF Service through jQuery AJAX call with GET method. So, sometimes the URL is lengthy with parameters.

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

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.

错误请求 - 无效网址

HTTP 错误 400.请求 URL 无效.

HTTP Error 400. The request URL is invalid.

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

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.

有没有人遇到过同样的情况并找到了解决办法?是 Windows 限制还是可以通过任何设置以编程方式进行管理?

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

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

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

编辑

我已测试生成错误的 URL

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

未编码的 URL 版本:

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

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

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.

我在 Windows 8 Professional 中的 Visual Studio 2012 Premium 中运行我的应用程序,因此它是 .NET 4.5 和 IIS Express.

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.

进一步研究

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

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.

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

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"}]

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

If I delete 1 character from this, it works.

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

Is it Browser Limitation? OS Limitation?

更新:解决方案

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

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.

这是一个 IIS 设置

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

The problem is because, the default character limit of each parameter in REST url is 260 which is defined in the registry.

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

So, you have to update the registry to increase this size limit where the IIS Server / IIS Express is running.

以下是注册表的位置:

HKEY_LOCAL_MACHINESYSTEMCurrentControlSetservicesHTTPParameters

值名称为 UrlSegmentMaxLength.如果它不存在,请创建一个 REG_DWORD 类型.并为 value data 指定更高的值,例如十六进制 1000 或十进制 4096.

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.

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

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.

推荐答案

将更新重新发布为 Answer,因为你们中的一些人可能会直接跳到 Answers 部分.

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

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.

这是一个 IIS 设置

This is an IIS Setting

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

The problem is because, the default character limit of each parameter in REST url is 260 which is defined in the registry.

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

So, you have to update the registry to increase this size limit where the IIS Server / IIS Express is running.

以下是注册表的位置:

HKEY_LOCAL_MACHINESYSTEMCurrentControlSetservicesHTTPParameters值名称是 UrlSegmentMaxLength.如果它不存在,请创建一个类型为 REG_DWORD 的.并为值数据指定更高的值,例如十六进制 1000 或十进制 4096.

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

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

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 URL 长度限制问题:错误请求 - 无效 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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