WCF REST - IIS6 的流式处理问题
本文关键字:处理问题 IIS6 REST WCF | 更新日期: 2023-09-27 17:55:12
>我正在尝试使用WCF REST将文件流式传输到服务器。当我在控制台上托管应用程序时,流去了文件。即,当我在循环中发送字节(读取要发送的文件)并在服务器端保留调试器时,该服务曾经在每次循环中都会受到打击。但是现在我已经在 IIS 6 上托管了该服务,只有当我关闭流时,该服务才会命中。这是某个 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 to false(有一个 性能冲击不断打开 和关闭连接)
2) 扩展超时属性: WebRequest.ReadWriteTimeout, WebRequest.Timeout, RequestStream.WriteTimeout,以及 RequestStream.ReadTimeout.
模拟问题的原始答案。