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

  • Home
  • SEARCH
  • 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 8090549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:45:37+00:00 2026-06-05T19:45:37+00:00

This is a severe problem in my application for some months with out finding

  • 0

This is a severe problem in my application for some months with out finding any good solution.
I noticed that C# manage the way Stream class is streaming in WCF, without considering my configuration.

Firstly, I have a class that inherit from FileStream so I can watch how much was read until now from the client side at anytime:

public class FileStreamWatching : FileStream
    {
        /// <summary>        
        /// how much was read until now        
        /// </summary>        
        public long _ReadUntilNow { get; private set; }
        public FileStreamWatching(string Path, FileMode FileMode, FileAccess FileAccess)
            : base(Path, FileMode, FileAccess)
        {
            this._ReadUntilNow = 0;
        }
        public override int Read(byte[] array, int offset, int count)
        {
            int ReturnV = base.Read(array, offset, count);
            //int ReturnV = base.Read(array, offset, count);
            if (ReturnV > 0)
            {
                _ReadUntilNow += ReturnV;
                Console.WriteLine("Arr Lenght: " + array.Length);
                Console.WriteLine("Read: " + ReturnV);
                Console.WriteLine("****************************");
            }
            return ReturnV;
        }
    }

Secondly, below is my service method of reading the client’s stream that contain the file.
My main problem is that FileStreamWatching.Read does not start for each time I summon it from this method below, instead FileStreamWatching.Read start one time for each X times I call it.. Strange.

*Look at the out put later

    public void Get_File_From_Client(Stream MyStream)
    {
        using (FileStream fs = new FileStream(@"C:\Upload\" + "Chat.rar", FileMode.Create))
        {
            byte[] buffer = new byte[1000];
            int bytes = 0;
            while ((bytes = MyStream.Read(buffer, 0, buffer.Length)) > 0)
            {
                fs.Write(buffer, 0, bytes);
                fs.Flush();
            }
        }
    }

This is the output at the client side for each time FileStreamWatching.Read is activated:(Remmber the buffer lenght is only 1000!)

Arr Lenght: 256,
Read: 256


Arr Lenght: 4096,
Read: 4096


Arr Lenght: 65536,
Read: 65536


Arr Lenght: 65536,
Read: 65536


Arr Lenght: 65536,
Read: 65536


Arr Lenght: 65536,
Read: 65536


….Until the file transfare is complete.

Problems:

  1. The Lenght of the buffer I brought to the read method isnt 256/4096/65536. It is 1000.
  2. The Read from the FileStreamWatching class does not start each time I call it from the service.

My goals:

  1. Controling on how much I reacive from the client for each read.

  2. The FileStreamWatching.Read will start each time I call it from the service.

My Client configuration:

<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IJob" transferMode="Streamed"/>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:8080/Request2" binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBinding_IJob" contract="ServiceReference1.IJob"
                name="BasicHttpBinding_IJob" />
        </client>
    </system.serviceModel>
</configuration>

My service configuration (There is no configuration file here):

        BasicHttpBinding BasicHttpBinding1 = new BasicHttpBinding();
        BasicHttpBinding1.TransferMode = TransferMode.Streamed;
        //
        BasicHttpBinding1.MaxReceivedMessageSize = int.MaxValue;
        BasicHttpBinding1.ReaderQuotas.MaxArrayLength = 1000;
        BasicHttpBinding1.ReaderQuotas.MaxBytesPerRead = 1000;
        BasicHttpBinding1.MaxBufferSize = 1000;
        //
        ServiceHost host = new ServiceHost(typeof(JobImplement), new Uri("http://localhost:8080"));
        //
        ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
        behavior.HttpGetEnabled = true;
        //
        host.Description.Behaviors.Add(behavior);
        ServiceThrottlingBehavior throttle = new ServiceThrottlingBehavior();
        throttle.MaxConcurrentCalls = 1;
        host.Description.Behaviors.Add(throttle);
        //
        //
        host.AddServiceEndpoint(typeof(IJob), BasicHttpBinding1, "Request2");
        host.Open();
  • 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-05T19:45:40+00:00Added an answer on June 5, 2026 at 7:45 pm

    re: why 256/4K/65535?

    I see two possibilities going on here:

    • The base FileStream is doing its own internal buffering. It may be internally calling read(array,offset,length) to fill its internal buffer, then passing back the portion you asked for. The internal calls end up being recursive, until it has read the entire file. Then your override stops displaying anything.
    • There are other stream.read() signatures you don’t show as being overridden. If any code path ends up calling one of the other read methods, then your counts will be off.

    re: MyStream not starting over each time

    Is the MyStream argument ever disposed? or is it reused for a new stream? Your code only “restarts” in the constructor, so be sure the object is disposed and re-constructed when you change incoming streams.

    You can test for the recursive EOF case by also displaying something when EOF is reached.

    You can test for unexpected recursion if you add static variables counting both the application calls to MyStream.Read and the method entry/exit. If they don’t match, then FileStream is making internal (accidentally recursive) calls.

    -Jesse

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I will apologize in advance as this post is born out of severe frustration.
This must be a very simple solution that has eluded me this last hour.
This is a super simple issue that I can't figure out. I want to
I'm writing an application that do some task and inform user upon successful completion
I am running a JSP/Servlet Web application and out of nowhere we experienced some
I have a severe problem with my database connection in my web application. Since
This question is language independent. I have an application that handles requests in a
I have recently joined a group with some severe JUnit testing issues. One problem
I'm writing an application that draws certain shapes. Before each shape is drawn, some
Okay so I thought I had solved this problem. But the solution still evades

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.