[英]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.