1

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

Ankit
  • 6,388
  • 8
  • 54
  • 79
  • Perhaps try calling Flush() on the stream as a quick fix? – oleksii May 04 '11 at 14:41
  • My code gives an error while sending the bytes in the stream using Stream.Write. It gives error - The request was aborted: The request was canceled. after ~2 mins – Ankit May 04 '11 at 14:55
  • Is it after you call flush? Can you please post your error and perhaps a few lines of code near that error? – oleksii May 04 '11 at 15:00
  • Edited the code with client code and place where i am getting error – Ankit May 04 '11 at 15:16

1 Answers1

1

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.

Community
  • 1
  • 1
oleksii
  • 35,458
  • 16
  • 93
  • 163
  • That too didnt worked. The same problem still there. Even on my local, i am getting timeout. – Ankit May 05 '11 at 05:10