Click here to Skip to main content
15,891,021 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a wcf rest service with Stream as input parameter:

C#
[OperationContract]
   [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
   void ImportStream(Stream data);


And this is my text as input in POSTMAN:

HTML
D_CA,P_AMOUNT,D_AN,D_PE,D_RU,D_NU,D_CO,D_MU,D_PMU,D_DP,P_COMMENT                              
A,100,,2019.12,S000,S000,S002,EUR,ORIG07-01,0000.PACKAGE,,,,,,2019.12,           
A,100,,2019.12,S000,,S004,EUR,ORIG07-01,0000.PACKAGE,,,,,,2019.12, 


As result, I have textRead:
HTML
"_CA,P_AMOUNT,D_AN,D_PE,D_RU,D_ORU,D_AC,,D_GO,D_LE,D_NU,D_CO,D_MU,D_PMU,D_DP,P_COMMENT     ....... "


As you see the first Character 'D' is missing !?

How can I fix it ? Thanks

What I have tried:

C#
public void ImportStream(Stream data)
    {
        if (data.ReadByte() != -1)
        {                
            using (var reader = new StreamReader(data))
            {                               
                string textRead = reader.ReadToEnd();
            }
        }
}
Posted
Updated 10-Jan-20 2:58am

1 solution

According to the documentation here: Stream.ReadByte Method (System.IO) | Microsoft Docs[^], the ReadByte() Method is going to read the first byte of the stream, and advance by one, meaning
C#
using (var reader = new StreamReader(data))
will be processed from data[1], instead of data[0].
 
Share this answer
 
v2
Comments
Member 14601214 10-Jan-20 9:12am    
Thanks for your reply, it is clear ,
I understand now ,
This is my code :

using (var reader = new StreamReader(data))
{

string allStreamString= reader.ReadToEnd();

}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900