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 3793214
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:44:28+00:00 2026-05-19T12:44:28+00:00

I have an ASMX(no WCF) webservice with a method that responses a file that

  • 0

I have an ASMX(no WCF) webservice with a method that responses a file that looks like:

[WebMethod]
public void GetFile(string filename)
{
    var response = Context.Response;
    response.ContentType = "application/octet-stream";
    response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName);
    using (FileStream fs = new FileStream(Path.Combine(HttpContext.Current.Server.MapPath("~/"), fileName), FileMode.Open))
    {
        Byte[] buffer = new Byte[256];
        Int32 readed = 0;

        while ((readed = fs.Read(buffer, 0, buffer.Length)) > 0)
        {
            response.OutputStream.Write(buffer, 0, readed);
            response.Flush();
        }
    }
}

and I want to download this file to local filesystem using web reference in my console application. How to get the filestream?

P.S. I tried download files via post request(using HttpWebRequest class) but I think there is much more elegant solution.

  • 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-05-19T12:44:29+00:00Added an answer on May 19, 2026 at 12:44 pm

    You can enable HTTP in the web.config of your web service.

        <webServices>
            <protocols>
                <add name="HttpGet"/>
            </protocols>
        </webServices>
    

    Then you should be able to just use a web client to download the file (tested with text file):

    string fileName = "bar.txt"
    string url = "http://localhost/Foo.asmx/GetFile?filename="+fileName;
    using(WebClient wc = new WebClient())
    wc.DownloadFile(url, @"C:\bar.txt");
    

    Edit:

    To support setting and retrieving cookies you need to write a custom WebClient class that overrides GetWebRequest(), it’s easy to do and just a few lines of code:

    public class CookieMonsterWebClient : WebClient
    {
        public CookieContainer Cookies { get; set; }
    
        protected override WebRequest GetWebRequest(Uri address)
        {
            HttpWebRequest request = (HttpWebRequest)base.GetWebRequest(address);
            request.CookieContainer = Cookies;
            return request;
        }
    }
    

    To use this custom web client you would do:

    myCookieContainer = ... // your cookies
    
    using(CookieMonsterWebClient wc = new CookieMonsterWebClient())
    {
        wc.Cookies = myCookieContainer; //yum yum
        wc.DownloadFile(url, @"C:\bar.txt");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASMX webservice that returns XElement - (not an .svc WCF service)
I have a .NET web service (using asmx...have not upgraded to WCF yet) that
I have a webservice (asmx file) in a directory requiring form authentication When I
we have a public asmx service that is accessed by our clients through SOAP
I have a web service (ASMX) and in it, a web method that does
I've written an ASP.NET webservice (.asmx style rather than WCF) and I have the
Hello I have a simple wcf service like this, with a test method which
I have a simple WCF webservice client that sends a request to Microsoft Search
we currently have an asmx webservice which exposes a single method to make various
Can ASMX have an IOC like WCF? Basically I want to be able to

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.