开发者

WCF REST - Streaming issue with IIS6

I am trying to stream file to server using WCF REST. When i hosted the application on a console , the streaming went file. I.E. when i sent the bytes in a loop (reading the file to be sent), and keep a debugger on the server end, the service used to get hit with every loop. But now that i have hosted the service on IIS 6, the service is hit only when i close the stream. Is this some IIS6 issue or am i doing something wrong?

Following is the 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>

Please help

Edit :

Plaing the client code:

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();
            }

Error happens at code "st.Write(buf, 0, bytesRead);" which says - The request was aborted: The request was canceled. after ~2 mins


Have you tried this?

1) Set the KeepAlive property of the HttpWebRequest to false (there is a performance hit to constantly opening and closing connections)

2) Extend the Timeout properties: WebRequest.ReadWriteTimeout, WebRequest.Timeout, RequestStream.WriteTimeout, and RequestStream.ReadTimeout.

Original answer to the simillar problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜