0

我找到了离我的问题不远的帖子,但仍然无法解决这个问题,所以请不要说它是重复的并尝试提供帮助。

我在 Azure 上托管了一个 Web 服务。

当调用具有大量(不是那么大)数据的特定方法时,我得到一个一般错误:“底层连接已关闭:接收时发生意外错误。”

我知道这是与大小相关的,因为请求中有一个大字符串,当它大约 4.5 MB 时一切正常,当请求大约 5 MB 或更高时,请求失败并出现一般错误。

据我所知,web.config 的大小最大:

<bindings>
  <webHttpBinding>
    <binding name="myWebHttpBinding" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" receiveTimeout="00:05:00" closeTimeout="00:05:00" openTimeout="00:05:00" sendTimeout="00:05:00"  >
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647"
                    maxNameTableCharCount="2147483647" />
      <security mode="Transport">
        <transport clientCredentialType="None"/>
      </security>
    </binding>
  </webHttpBinding>
</bindings>

这是方法的声明方式:

[WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, Method = "POST", UriTemplate = "/PublishDataItems")]
        ServerRespones PublishDataItems(DataItemRequest Request);

这就是我从客户端调用该方法的方式:

WebClient proxy = new WebClient();
            proxy.Headers["Content-type"] = "application/json";
            MemoryStream ms = new MemoryStream();
            DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(DataItemRequest));
            ser.WriteObject(ms, myRequest);
            byte[] data = proxy.UploadData(URL + "PublishDataItems", "POST", ms.ToArray());
            MemoryStream stream = new MemoryStream(data);
            DataContractJsonSerializer obj = new DataContractJsonSerializer(typeof(ServerRespones));
            var result = obj.ReadObject(stream) as ServerRespones;
4

2 回答 2

0

您可能会看到负载均衡器超时。关于断开连接之前的持续时间的详细信息并不多,但您的问题可能与请求持续时间而不是大小有关。请查看此 MSDN 博客条目以了解更多详细信息。

于 2013-10-22T11:32:01.900 回答
0

默认的 WCF 传输模式是缓冲的,更改为流模式。

http://msdn.microsoft.com/en-us/library/ms731913.aspx

http://msdn.microsoft.com/en-us/library/ms789010.aspx

http://msdn.microsoft.com/pt-br/library/ms733742.aspx

于 2013-10-22T11:59:38.100 回答