我有这个以JSON格式提交给WCF的对象
var j= {
"Omschrijving": escape(encodeURI(document.getElementById('descr').value.trim())),
"Foto" : "...", // VERY LONG STRING HERE (150 000 characters),
"XCo": pLocation.x,
"YCo": pLocation.y,
"user": login,
"Adres":escape(encodeURI(document.getElementById('map-location').innerHTML)),
"Type": $('#meldingType').val()
};
为了解决这个问题,已删除了foto属性。它大约有150k个字符。
这是从我的phonegapp应用程序调用WCF的请求:
function corsRequest(j, url){
response = "-9";
var xhr = createCORSRequest('POST', url);
if (!xhr) {
navigator.notification.alert("Gelieve een andere internetbrowser als standaard in te stellen.", null, "Fout");
return;
}
// Response handlers.
xhr.onload = function () {
response = xhr.responseText;
};
//xhr.send(JSON.stringify(j).replace(/"/g, '\''));
var notJson = '"'+JSON.stringify(j).replace(/"/g, '\'')+'"';
//alert(notJson);
xhr.setRequestHeader("Content-type", "application/json");
xhr.send(notJson);
我将此作为web.config
<basicHttpBinding>
<binding name="crossDomain" maxReceivedMessageSize="10485760">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</basicHttpBinding>
<webHttpBinding>
<binding name="crossDomain" crossDomainScriptAccessEnabled="true" maxReceivedMessageSize="10485760">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</webHttpBinding>
[...]
<services>
<service name="CeviService.CeviSpotter" behaviorConfiguration="MyServiceTypeBehaviors">
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex"/>
<endpoint address="ajaxEndpoint" binding="webHttpBinding" contract="CeviService.ICeviSpotter" behaviorConfiguration="AjaxBehavior" bindingConfiguration="crossDomain">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</service>
</services>
问题在于:当我提交一个长JSON字符串(150k +字符)时,它在localhost上完美运行。它给了我成功提交应该返回的价值。但是,当Web服务联机时,我得到的响应(如果建立服务器连接或20秒后(超时)则会发出警报)为空。这很奇怪,因为响应在开始时设置为-9。如果20秒后响应仍为-9,则表示服务器超时。如果它是-1(由服务器设置),则存在服务器错误(如语法错误或其他内容)。如果为1,则命令和功能成功执行。因此它显示的警报只是空的。并且值不会提交到数据库。
现在,我做错了什么,还是因为服务器设置? (它适用于localhost,但不是我在线时)
提前致谢
编辑:WCF被try-catch包围,所以没有办法有空响应
答案 0 :(得分:1)
确保在客户端和服务器web.config文件的绑定标记上正确设置了maxReceivedMessageSize属性。
服务器web.config:
<bindings>
<basicHttpBinding>
<binding closeTimeout="04:01:00"
openTimeout="04:01:00" receiveTimeout="04:10:00" sendTimeout="04:01:00"
maxBufferSize="2147483647" maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647"
messageEncoding="Text" textEncoding="utf-8">
<readerQuotas maxDepth="32" maxStringContentLength="2147483647"
maxArrayLength="16348" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</binding>
</basicHttpBinding>
</bindings>
客户端web.config:
<basicHttpBinding>
<binding name="BasicHttpBinding_IMainService" maxReceivedMessageSize="2147483647"/>
</basicHttpBinding>