Click here to Skip to main content
15,879,474 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Updated 16-Apr-13 0:28am
v2
Comments
cchubz 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<unsigned char>, 0, length)

then in java part
(Base64.decodeBase64(String.getBytes())

José is right about the soap standard about binary base64 encoding.

cheers

1 solution

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
 
Share this answer
 
Comments
Matthew Faithfull 16-Apr-13 6:33am    
Nice but the obvious question is why? Why is the base64 encoding necessary?
José Amílcar Casimiro 16-Apr-13 6:38am    
Binary files could have characters that are not allowed by soap protocol.
Matthew Faithfull 16-Apr-13 8:48am    
Thanks José, now many people can learn from your answer and I can vote it up.
José Amílcar Casimiro 16-Apr-13 8:50am    
:-)

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