Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ file service SOAP
hello! i have a c++ client source code as follows :
    // prepare request data
    Client_Operation::Client_OperationServiceRequest^ request = gcnew Client_Operation::Client_OperationServiceRequest();    
    System::IO::FileStream^ wcstream = gcnew System::IO::FileStream (gcnew System::String ( "D:\\sample.zip" ), System::IO::FileMode::Open);
    System::IO::BinaryReader^ wcbin = gcnew System::IO::BinaryReader (wcstream );    
    request->fileBytes = wcbin->ReadBytes (wcstream->Length);
 
    // call service
    Client_Operation::Client_OperationService^ service = gcnew Client_Operation::Client_OperationService();
    Client_Operation::Client_OperationServiceResponse^ response = service->clientRequest( request);
these source codes are suppose to read and send a zip file to the web service (the server is using java).
in the client side, data in sample.zip are read properly and stored to request->fileBytes.
 
however, value of request->fileBytes changes when retrieved in server side.
does anyone know how to send zip file bytes to server?
 
im sorry, i am new to c++ so im having a hard time fixing this one.
 
any comment/suggestion is highly appreciated.
 
thanks!
Posted 16-Apr-13 1:19am
cchubz413
Edited 16-Apr-13 1:28am
v2
Comments
cchubz at 17-Apr-13 1:37am
   
thank you very much José, you rocked..
 
For others wondering: The solution is simple.
C++ side (managed)
System::Convert::ToBase64String(array, 0, length)
 
then in java part
(Base64.decodeBase64(String.getBytes())
 
José is right about the soap standard about binary base64 encoding.
 
cheers

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,
 
You will need to encode your file in base64 BEFORE send it to the webservice.
From the webservice side (server side), it is necessary to decode the file from base64.
 
Cheers,
JAFC
  Permalink  
Comments
Matthew Faithfull at 16-Apr-13 6:33am
   
Nice but the obvious question is why? Why is the base64 encoding necessary?
   
Binary files could have characters that are not allowed by soap protocol.
Matthew Faithfull at 16-Apr-13 8:48am
   
Thanks José, now many people can learn from your answer and I can vote it up.
   
:-)

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 575
1 Kornfeld Eliyahu Peter 409
2 Maciej Los 369
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,353
1 DamithSL 4,854
2 Maciej Los 4,466
3 Kornfeld Eliyahu Peter 4,058
4 Sergey Alexandrovich Kryukov 3,897


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 16 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100