我有這個目標,我在JSON格式提交給WCF空響應 - 長JSON字符串
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()
};
的照片屬性已對這個問題的緣故刪除。它大約有15萬個字符。
這是從我的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 +字符),它在本地主機上完美工作。它給了我一個成功的提交應該返回的價值。但是,當web服務處於聯機狀態時,我收到的響應(如果服務器連接已建立或在20秒(超時)後會收到響應)爲空。這很奇怪,因爲響應在開始時設置爲-9。如果響應在20秒後仍爲-9,則表示服務器超時。如果它是-1(由服務器設置),則存在服務器錯誤(如語法錯誤或其他)。如果是1,則命令和函數成功執行。所以它顯示的警報只是空的。並且這些值不會被提交給數據庫。
現在,我做錯了什麼,或者是因爲服務器設置? (它的工作原理在本地主機上,而不是當我把它放到網上)
在此先感謝
編輯:WCF是由一個try-catch包圍,所以沒有辦法有一個空的響應