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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:10:07+00:00 2026-06-03T22:10:07+00:00

Im developing in WCF and inside my client code I creat filestream with a

  • 0

Im developing in WCF and inside my client code I creat filestream with a file to transfer to the service (by sending it as stream in message). After the service got the stream, he read it peace by peace and write it on new file; Service download the file from the client to him, thats all.

I override the method in filestream, Read, so I can know how much was readed in the client side, when the service is downloading in his side.

public class FileStreamEx : FileStream
    {
        public long _ReadUntilNow { get; private set; }
        public FileStreamEx(string path, FileMode mode, FileAccess access, FileShare share)
            : base(path, mode, access, share)
        {
            this._ReadUntilNow = 0;
        }
        public override int Read(byte[] array, int offset, int count)
        {
            int ReturnV = base.Read(array, offset, count);
            _ReadUntilNow += ReturnV;
            return ReturnV;
        }
    }

My goal is to know from the client side, how much was readed by the service every second.
This can be implemented by seeing the _ReadUntilNow value simply from the client becouse the service only use a reference to the FileStreamEx object.

My problem is that befor the service even start read the stream I gave him, the _ReadUntilNow value = size of the file. Only way for this to heppend is calling my overrided method, Read, befor I do.

My question is who call the Read befor me, why and what can I do to prevent it?

My client:

public static void CallService()
        {
            ServiceReference1.IJob Service1 = new ServiceReference1.JobClient(new InstanceContext(new CCBImplement()));
            DLL.FileStreamEx TheStream TheStream = new DLL.FileStreamEx(@"C:\Uploadfiles\Chat.rar", FileMode.Open, FileAccess.Read, FileShare.None);
            ServiceReference1.RemoteFile RemoteFile1=new ServiceReference1.RemoteFile("Chat.rar", TheStream.Length, @"C:\Uploadfiles\Chat.rar", TheStream);
            Service1.UselessMethod1(RemoteFile1);
            new Thread(new ThreadStart(Check_Only_ReadUntilNow_Every_Second)).Start();
        }

Service Code:

public void UselessMethod1(RemoteFile RemoteFile)
        {
            Stream MyStream = RemoteFile.FileByteStream;
            using (FileStream fs = new FileStream(@"C:\Upload\"+RemoteFile.FileName, FileMode.Create))
            {
                int bufferSize = 1 ; // 1 MB buffer
                byte[] buffer = new byte[bufferSize];
                int totalBytes = 0;
                int bytes = 0;
                while ((bytes = MyStream.Read(buffer, 0, bufferSize)) > 0)
                {
                    fs.Write(buffer, 0, bytes);
                    fs.Flush();
                    totalBytes += bytes;
                }
            }
        }

RemoteFile class:

[MessageContract]
    public class RemoteFile : IDisposable
    {
        [MessageHeader]
        public string FileName;

        [MessageHeader]
        public string Path;

        [MessageHeader]
        public long Length;

        [MessageBodyMember]
        public Stream FileByteStream;
        public RemoteFile() { }
        public RemoteFile(string FileName, string Path, long Length, Stream FileByteStream)
        {
            this.Path = Path;
            this.FileName = FileName;
            this.Length = Length;
            this.FileByteStream = FileByteStream;
        }
        public void Dispose()
        {
            if (FileByteStream != null)
            {
                FileByteStream.Close();
                FileByteStream = null;
            }
        }
    }
  • 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-03T22:10:09+00:00Added an answer on June 3, 2026 at 10:10 pm

    I think that his question is that:
    on side A, there is a service host with a method that read files on stream mode.
    on side B, there is a client that sends a file using this service.

    he expanded the FileStream calss to add a variable which holds the amount of bytes read from the file.

    he calls the service on side A, but before it even reaches the method- the extra variable holds the size of the whole file..which means the whole file was read.

    the question is why.

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

Sidebar

Related Questions

After developing mini project with WCF duplex (Chat Service | Sms Service), I got
I'm developing an Android client for a WCF service. There is a windows app
I am following WSDL-first (provided by our client) approach for developing WCF service but
I am currently developing a WCF duplex Service for 2 clients. The first client
I am developing the REST enabled WCF Service. I am using the following code
I am developing a WCF service on my local computer using Visual Studios built
I am currently developing a service with wcf 4.0 (visual studio 2010 RC). When
I have a WCF service method that calls a SQL stored proc. I'm developing
I'm developing client-server application by using .Net, C#, WCF, WPF. And now I need
I've been developing a WCF web service using .NET 3.5 with IIS7 and it

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.