I need to call asmx webservice, which takes an AttachmentData as a parameter. It has a member with type base64Binary.
<s:complexType name="AttachmentData"> <s:sequence> <s:element minOccurs="0" maxOccurs="1" name="FileName" type="s:string" /> <s:element minOccurs="0" maxOccurs="1" name="UploadedUserName" type="s:string" /> <s:element minOccurs="0" maxOccurs="1" name="Attachment" type="s:base64Binary" /> </s:sequence> </s:complexType>
I send the contents of the file for the Attachment element as follows:
//read the file contents byte[] buffer = null; try { FileInfo attachment = new FileInfo(filepath); using (FileStream stream = attachment.OpenRead()) { if (stream.Length > 0) { buffer = new byte[stream.Length]; stream.Read(buffer, 0, (int)stream.Length); } } } catch { buffer = null; } //create AttachmentData object WebSrvc.AttachmentData att = new WebSrvc.AttachmentData(); att.FileName = fileName; att.Attachment = buffer;
Is this the right way to send base64Binary? Do I need to encode the contents of the file to base64 or is it done on the fly? I am trying to see if I unnecessarily inflate the size of the webservice request using the code above.
source share