我已经写了一个C#Windows Service(.NET Framework 3.5,C#3.0),该服务将文件和HTML形式信息发布到远程服务器,然后将XML Server响应存储在数据库中。这是相关代码的主要部分:

    HttpWebRequest request = WebRequest.Create(postUrl) as HttpWebRequest;

    request.ProtocolVersion = HttpVersion.Version10;
    request.KeepAlive = false;
    request.Timeout = 600000;
    request.ReadWriteTimeout = 600000;
    request.Method = "POST";
    request.ContentType = contentType;
    request.UserAgent = userAgent;
    request.CookieContainer = new CookieContainer();
    request.ContentLength = formData.Length;

    using (Stream requestStream = request.GetRequestStream())
    {
        // Push it out there
        requestStream.Write(formData, 0, formData.Length);
        requestStream.Close();
    }

    return request.GetResponse() as HttpWebResponse;

我的服务适用于所有小文件,但是当我尝试发送较大的文件(8-9 MB)时,我会收到以下错误。

    The underlying connection was closed: An unexpected error occurred on a receive.

我使用Fiddler查看了即将发出的请求,并能够收集以下信息:

    HTTP/1.1 504 Fiddler - Receive Failure
    Content-Type: text/html
    Connection: close
    Timestamp: 12:25:04.067

    ReadResponse() failed: The server did not return a response for this request.

我打电话后7分钟发生故障 request.getResponse(). 。有什么方法可以确定谁关闭了连接?我还要尝试解决这个问题吗?提前致谢!

有帮助吗?

解决方案

由于您提到的是用于小文件的工作,但不大,我建议您检查服务器上的最大文件上传大小。我相信默认值为4MB。 http://support.microsoft.com/kb/295626

编辑:注意到上面的链接有些过时。这是IIS7的一个: http://www.cyprich.com/2008/06/19/fixing-file-upload-size-limit-in-iis-7/

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top