Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9070247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:38:17+00:00 2026-06-16T17:38:17+00:00

i am using WCF to upload and download a file. and i am using

  • 0

i am using WCF to upload and download a file. and i am using the following the for download.

try
        {
            MyService.IWITSService clientDownload = new WITSServiceClient();
            MyService.DownloadRequest requestData = new DownloadRequest();
            MyService.RemoteFileInfo fileInfo = new RemoteFileInfo();
            requestData.ItemID = Convert.ToInt32(Request.QueryString["id"]);

            fileInfo = clientDownload.DownloadFile(requestData);

            Response.BufferOutput = false;   // to prevent buffering 
            byte[] buffer = new byte[6500000];
            int bytesRead = 0;

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.ClearHeaders();
            HttpContext.Current.Response.ContentType = fileInfo.FileExt;
            HttpContext.Current.Response.AddHeader("Content-Disposition","attachment; filename=" + fileInfo.FileName);

            bytesRead = fileInfo.FileByteStream.Read(buffer, 0, buffer.Length);

            while (bytesRead > 0)
            {
                // Verify that the client is connected.
                if (Response.IsClientConnected)
                {

                    Response.OutputStream.Write(buffer, 0, bytesRead);
                    // Flush the data to the HTML output.
                    Response.Flush();

                    buffer = new byte[6500000];
                    bytesRead = fileInfo.FileByteStream.Read(buffer, 0, buffer.Length);

                }
                else
                {
                    bytesRead = -1;
                }
            }
        }
        catch (Exception ex)
        {
            // Trap the error, if any.
            System.Web.HttpContext.Current.Response.Write("Error : " + ex.Message);
        }
        finally
        {
            Response.Flush();
            Response.Close();
            Response.End();
            System.Web.HttpContext.Current.Response.Close();
        }

file is downloaded but file data is not display. file size is same as an actual
size. can any one help me where i have to change..
Thanks in advance..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T17:38:19+00:00Added an answer on June 16, 2026 at 5:38 pm

    You don’t want to call neither Response.Close() nor System.Web.HttpContext.Current.Response.Close(). It interrupts the connection to the client.

    The documentation of HttpResponse.Close Method says:

    This method terminates the connection to the client in an abrupt
    manner and is not intended for normal HTTP request processing. The
    method sends a reset packet to the client, which can cause response
    data that is buffered on the server, the client, or somewhere in
    between to be dropped.

    You might use this method in response to an attack by a malicious HTTP
    client. However, typically you should call CompleteRequest instead if
    you want to jump ahead to the EndRequest event and send a response to
    the client.

    So reduce the finally code to:

    finally
    {
        Response.Flush();
        Response.End();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to know how to upload a file using WCF by making
Hi Im using the following code: http://vikaskanani.wordpress.com/2011/01/11/android-upload-image-or-file-using-http-post-multi-part/ To POST an image to a WCF
I'm writing a WCF Service to Upload file using REST. But my probleme come
I have an upload/download web service that I created with WCF. Im using c
I am using a WCF to upload a file to a server. public interface
I have a WCF file upload service, which is using streamed mode. Is it
I am new to C++. I have written upload file wcf in c# and
I'm new to WCF , I want to Upload Multiple Images at a time
I'm trying to upload a complex object to a WCF webservice using KSoap2 Android
I've having a very simple WCF service (a console application for file upload). I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.