How to send an array of byte to a web service thru a smart object


Badge +3

Hello,

 

I need to send a file to a web service. I am not the web service owner and I cannot change it (so I cannot take in a base64 string and convert in the web service later on).

 

I am using the Endpoinst WebService and the service instance shows that it expects to pass a Memo to the web service as Byte [][].

I tried passing the Base64 encoded string of my file to this method but it fails and tells me that it is "Unable to deserialize value Byte[][]".

 

I saw that the Service Instance generated serialization helper methods including one that can serialize a Byte into an array of Byte but this no realistic to pass the Byte one by one!

 

How can I convert my base64 to something acceptable for the smo/web service ?


7 replies

Badge +5

Hi, WilfriendKopp


 


I found something you can look at from our documentation and previous community post.


 



 



 


hope this help.


 


 


 


Regards


 


Julia

Badge +3

Hello,

 

Thanks for your help.

I don´t see the first link we related to my question. It is interesting though :)

 

As far the second link it concerned, it is also very valuable information when using SmartForms and having the control over the Web Service (to change it), which is not my case.

 

So this does not help but I appreciate the links :)

 

Will

Badge +1

Hi,

 

I'm having the same issue as the OP.  I am trying to call an external web service that I can't modify and it requires a file passed in as a byte array.

 

There doesn't seem to be a resolution to this on this thread.  Has anyone found a way around this?

 

Regards

Phil

Badge +10

You may already know this but a K2 file object follows the xml format

 

<File>

<Name></Name>

<Content></Content>

</File>

 

The content tag contains the actual file encoded in base64. Have you tried decoding only the values i the content tag and passing that to the webservice.

 

Example: i have previously written a web handler in c# allowing users to download K2 file attachments: see below for code snippet

 

attachment input is a memo, contains the file witht eh structure shown above as a string.

 

        private void GetFileFromXML(out byte[] fileContent, out string fileName, string attachment)
{
fileContent = null;
fileName = null;

var xDocument = XDocument.Parse(attachment);

var file = (from x in xDocument.Descendants("file")
select new
{
FileName = x.Element("name").Value,
FileContent = x.Element("content").Value
}).FirstOrDefault();

fileName = file.FileName;
fileContent = Convert.FromBase64String(file.FileContent.ToString());
}

I hope that help as little.

Badge +1

My problem isn't so much with getting the base64 string, I can use the inline functions for that.  The issue is how to serialize it to the JSON format that the enpoint broker needs.  I have a slightly dirty workaround where I concatonate the JSON strings around the base64 content to "serilize" it.  It works but it would be nice to have serialize/de-serialize byte array methods.

 

While not directly relevant, the xml file structure is very useful information, thanks!

Badge +10

I see. I only just saw that you are using the  Endpoinst WebService Service Type. What type of webservice is it. Rest?

If all fails, have you considered.creating a custom service object and then calling the webservice through that. 

Badge +1

I'm having the same issue where I want to convert the base-64 string to byte so that it can be passed to the web service. How did you concatenate the Json strings to the base-64 content? Could you explain?

Reply