我想使用WCF REST将文件流式传输到服务器。当我在控制台上托管应用程序时,流传输文件。 I.E.当我在一个循环中发送字节(读取要发送的文件)时,并在服务器端保留一个调试器,该服务用于在每个循环中进行命中。但是现在我已经在IIS 6上托管了该服务,该服务仅在关闭该流时才被击中。这是一些IIS6问题还是我做错了什么?WCF REST - 与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分钟后
也许尝试调用流上的Flush()作为快速修复? – oleksii 2011-05-04 14:41:17
我的代码在使用Stream.Write发送流中的字节时发生错误。它给出错误 - 请求被中止:请求被取消。约2分钟后 – Ankit 2011-05-04 14:55:14
是否在您调用flush之后?你可以在错误附近张贴你的错误,也许还有几行代码? – oleksii 2011-05-04 15:00:52