我想使用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