在线WCF的空响应-长json字符串

问题描述 投票:2回答:1

我有这个对象,我以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属性已被删除。它约有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 +个字符)时,它在localhost上运行良好。它给了我成功提交时应该返回的值。但是,当Web服务联机时,我得到的响应(如果服务器连接已建立或20秒(超时)后将得到警告)为空。这很奇怪,因为响应开始时设置为-9。如果20秒后响应仍为-9,则服务器超时。如果它是-1(由服务器设置),则表示服务器错误(例如语法错误或其他错误)。如果为1,则命令和功能已成功执行。因此,它显示的警报为空。值不会提交到数据库。

现在,我是在做错什么,还是因为服务器设置? (它可以在localhost上运行,但是当我将其放在网上时不可以)

提前感谢

编辑:WCF被try-catch包围,所以不可能有空响应

javascript jquery wcf
1个回答
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>
© www.soinside.com 2019 - 2024. All rights reserved.