繁体   English   中英

WCF REST - IIS6 的流式传输问题

[英]WCF REST - Streaming issue with IIS6

我正在尝试使用 WCF REST 将 stream 文件发送到服务器。 当我在控制台上托管应用程序时,流式传输文件。 IE 当我在循环中发送字节(读取要发送的文件)并在服务器端保留一个调试器时,该服务用于在每个循环中受到打击。 但是现在我已经在 IIS 6 上托管了该服务,只有在我关闭 stream 时才会触发该服务。 这是一些 IIS6 问题还是我做错了什么?

以下是 web.config:

<system.web>
    <compilation debug="true" targetFramework="4.0" />
    <pages validateRequest="false" />
    <httpRuntime  maxRequestLength="102400" executionTimeout="3600" requestValidationMode="2.0" requestPathInvalidCharacters="" />

</system.web>

<system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
    <bindings>
        <webHttpBinding>
            <binding name="streamWebHttpBinding" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" receiveTimeout="01:00:00" sendTimeout="01:00:00" transferMode="Buffered" />
        </webHttpBinding>
    </bindings>
    <behaviors>
        <serviceBehaviors>
            <behavior name="FileUpload.FileUploadBehavior">
                <serviceMetadata httpGetEnabled="true"/>
                <serviceDebug includeExceptionDetailInFaults="true"/>
            </behavior>
        </serviceBehaviors>
        <endpointBehaviors>
            <behavior name="RestBehavior">
                <webHttp />
            </behavior>
        </endpointBehaviors>
    </behaviors>
    <services>
        <service name="FileUpload.UploadData" behaviorConfiguration="FileUpload.FileUploadBehavior" >
            <endpoint behaviorConfiguration="RestBehavior" address="" contract="FileUpload.IUpload" binding="webHttpBinding" bindingConfiguration="streamWebHttpBinding" />
        </service>
    </services>
</system.serviceModel>

请帮忙

编辑:

放置客户端代码:

HttpWebRequest req = GetWebRequest("asyncfileupload", fileName);
            // 64 KB buffer
            byte[] buf = new byte[0x10000];
            Stream st = req.GetRequestStream();
            int bytesRead;

            using (FileStream fs = new FileStream(filepath, FileMode.Open, FileAccess.Read))
            {
                bytesRead = fs.Read(buf, 0, buf.Length);
                while (bytesRead > 0)
                {
                    st.Write(buf, 0, bytesRead);
                    bytesRead = fs.Read(buf, 0, buf.Length);
                }
                st.Close();
            }

错误发生在代码“st.Write(buf, 0, bytesRead);” 它说 - 请求被中止:请求被取消。 约 2 分钟后

你试过这个吗?

1) 将 HttpWebRequest 的 KeepAlive 属性设置为 false(不断打开和关闭连接会对性能造成影响)

2) 扩展超时属性:WebRequest.ReadWriteTimeout、WebRequest.Timeout、RequestStream.WriteTimeout、RequestStream.ReadTimeout。

类似问题的原始答案

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM