【问题标题】:Empty response from online WCF - long json string来自在线 WCF 的空响应 - 长 json 字符串
【发布时间】:2013-05-02 08:30:01
【问题描述】:

我有这个以 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,则命令和函数已成功执行。所以它显示的警报只是空的。并且这些值不会提交到数据库。

现在,我做错了什么,还是因为服务器设置? (它在本地主机上工作,但当我把它放在网上时)

提前致谢

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

【问题讨论】:

    标签: javascript jquery wcf


    【解决方案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>
    

    【讨论】:

      猜你喜欢
      • 2018-08-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多