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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:04:16+00:00 2026-06-04T02:04:16+00:00

First of all, I made my problem as simple as I could to show

  • 0

First of all, I made my problem as simple as I could to show you that, in simple words, when I transfare a stream object in wcf, the method ‘Read’ dont care about any parameters I give him.

I have WCF client & service, TransferMode = Streamed on both sides. basicHttpBinding.
The client send to the service a Stream object and the service read the stream and write it on a new file that he create.
The client send a subclass of stream that I created : FileStreamEx that inherit from FileStream.

I puted this class in that namespace so I can watch everytime the service call ‘Read’ method.

namespace ConsoleApplication1
{
    /// <summary>
    /// The only thing I gain from this class is to know how much was read after every time I call "Read" method
    /// </summary>
    public class FileStreamEx : FileStream
    {
        /// <summary>
        /// how much was read until now
        /// </summary>
        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;
            Console.WriteLine("Read: " + _ReadUntilNow);//Show how much was read until now
            return ReturnV;
        }
    }
    public class Program
    {
        static void Main(string[] args)
        {
            ServiceReference1.IJob Service1 = new ServiceReference1.JobClient();
            string FileName = "Chat.rar";
            string Path = @"C:\Uploadfiles\";
            FileStreamEx TheStream = new FileStreamEx(Path + FileName, FileMode.Open, FileAccess.Read, FileShare.None);
            Service1.UselessMethod1(TheStream);
        }
    }
}

Until now there is nothing complicated. Below there is the UselessMethod1 method code.
But befor that, The problem allready started: After I call Service1.UselessMethod1(TheStream), Insted of going to the UselessMethod1 method, the ‘Read’ method begin 3 times, no matter what the size of the file and the out put is (Only on the client side):

Read: 256

Read: 4352

Read: 69888

And only after the ‘Read’ method gets called 3 times, the UselessMethod1 Begin.
If you will look at the code below, You will see that My buffer arr size is only 1024 for each Read!
By logic, after MyStream.Read(buffer, 0, bufferSize)), My ‘Read’ method need to begin but this is not the case, the ‘Read’ method start randomaly (or not, I cant understand it) and when my ‘Read’ method begin, the Length of the Arr of the parameter ‘byte[] array’ that my ‘Read’ method have is never 1024 when it gets called.

public void UselessMethod1(Stream MyStream)
        {
            using (FileStream fs = new FileStream(@"C:\Upload\"+"Chat.rar", FileMode.Create))
            {
                int bufferSize = 1024 ;
                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;
                }
            }
        }

Some of the out put in this code is:
(Sory I didnt understand how to show image)
http://desmond.imageshack.us/Himg36/scaled.php?server=36&filename=prlbem.jpg&res=landing

But in my logic, the out put of this code need to be from the start:

Read: 1024

Read: 1024

Read: 1024

Read: 1024

Read: 1024

Read: 1024

…

..

.

But its not the out out! Where is my mistake? Is there even any miskate?

  • 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-04T02:04:18+00:00Added an answer on June 4, 2026 at 2:04 am

    The server and the client may (and will likely) use different buffer sizes when reading the data. There’s nothing wrong per se with your code.

    If you want to force the client to use a smaller buffer, you can consider making the binding’s transfer mode Streamed, and use a small value for the MaxBufferSize property of the binding (if you’re using a custom binding, those properties will likely be on the transport binding element).

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

Sidebar

Related Questions

First of all my tree is made up of nodes that look like this:
First of all, is this possibly ready-made? Hibernate 3.6 , JDBC batch_size 500 ,
First of all, I'm new to objective-c programming so I've probably made some mistakes
First off thanks to all the users who have made my android developing adventure
first of all, i am sorry that even if there's many given topic that
I made a system that creates a simple string with Function/Response format, example: Check('Value'):ShowImage(@)|Check('Value'):OtherFunction(@)....and
First of all, this isn't for a keylogger, it's for an input in a
first of all some details: I configured security as below in web.xml view plaincopy
First of all, I'm quite new to the Android and JAVA world (coming from
first of all i would like to say i know its probably an easy

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.