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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:04:06+00:00 2026-06-01T23:04:06+00:00

I have a simple web service and I want to make a method which

  • 0

I have a simple web service and I want to make a method which will return me a single text file. I did that this way:

    public byte[] GetSampleMethod(string strUserName)
    {
        CloudStorageAccount cloudStorageAccount;
        CloudBlobClient blobClient;
        CloudBlobContainer blobContainer;
        BlobContainerPermissions containerPermissions;
        CloudBlob blob;
        cloudStorageAccount = CloudStorageAccount.DevelopmentStorageAccount;
        blobClient = cloudStorageAccount.CreateCloudBlobClient();
        blobContainer = blobClient.GetContainerReference("linkinpark");
        blobContainer.CreateIfNotExist();
        containerPermissions = new BlobContainerPermissions();
        containerPermissions.PublicAccess = BlobContainerPublicAccessType.Blob;
        blobContainer.SetPermissions(containerPermissions);
        string tmp = strUserName + ".txt";
        blob = blobContainer.GetBlobReference(tmp);
        byte[] result=blob.DownloadByteArray();
        WebOperationContext.Current.OutgoingResponse.Headers.Add("Content-Disposition", "attachment; filename="+strUserName + ".txt");
        WebOperationContext.Current.OutgoingResponse.ContentType = "text/plain";
        WebOperationContext.Current.OutgoingResponse.ContentLength = result.Length;
        return result;
    }

…and from service interface:

    [OperationContract(Name = "GetSampleMethod")]
    [WebGet(UriTemplate = "Get/{name}")]
    byte[] GetSampleMethod(string name);

And it returns me a test file containing XML response.
So the question is: how do I return a file without XML serialization?

  • 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-01T23:04:08+00:00Added an answer on June 1, 2026 at 11:04 pm

    Change your method to return a Stream instead. Also, I would suggest not downloading the entire content to a byte[] before returning it. Instead just return the stream from the Blob. I’ve attempted to adapt your method, but this is freehand code so it may not compile or run as-is.

    public Stream GetSampleMethod(string strUserName){
      //Initialization code here
    
      //Begin downloading blob
      BlobStream bStream = blob.OpenRead();
    
      //Set response headers. Note the blob.Properties collection is not populated until you call OpenRead()
      WebOperationContext.Current.OutgoingResponse.Headers.Add("Content-Disposition", "attachment; filename="+strUserName + ".txt");
      WebOperationContext.Current.OutgoingResponse.ContentType = "text/plain";
      WebOperationContext.Current.OutgoingResponse.ContentLength = blob.Properties.Length;
    
      return bStream;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a simple web-service using Java. i want to load jars related
I have a simple web service that uses an oracle database. When I test
I have a simple web service that has an API third party developers are
Pretty simple scenario. I have a web service that receives a byte array that
I have a simple web service operation like this one: [WebMethod] public string HelloWorld()
I have a simple web service call, generated by a .NET (C#) 2.0 Windows
I have a simple WCF Web service. It's hosted on IIS under the default
I have a simple task. I have an existing project with a web service
I have a simple WCF service that I call server side from code behind
I have a ASP.NET web service decorated with System.Web.Script.Services.ScriptService() so it can return json

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.