JohanL
Apprentice

Endpoints WebService Service Object and file uploads

Good day,


I have a web service (normal asmx) which takes as an argument a byte array for a file upload.


When I try to point the Endpoints WebSerivce to this web service the type is generated as a Memo datatype.


How can I change the web service to allow the service instance to pick it up as a file? Is this a supported type of the Endpoints webservice service object?


Please let me know,


Regards,

0 Kudos
Reply
5 Replies
JohanL
Apprentice

Re: Endpoints WebService Service Object and file uploads

I managed to solve this with the help from Samuel at K2.


He advised that SmartObjects handle files with an XML structure containing the filename and the content as a Base64 string.
I then changed my smartobject property to be of the "File" type and then changed my web service to accept this property as string.
In my web service method I then converted it to XML and then converted the content from Base64 to a byte array and saved it to the back-end system.


Using this work-around I was able to submit files using this smartobject.


I hope this will help someone else who is struggling with the same thing.

Reply
Nagorskiy
Apprentice

Re: Endpoints WebService Service Object and file uploads

Hi, Johan.


First of all thank you for posting here.


Сould you post some example your solution? I would like to reproduce the same web service.
Did you use this with smartforms?  


 

0 Kudos
Reply
Phil-Hawkins
Novice

Re: Endpoints WebService Service Object and file uploads

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

0 Kudos
Reply
Phil-Hawkins
Novice

Re: Endpoints WebService Service Object and file uploads

0 Kudos
Reply
s0m3one
Apprentice

Re: Endpoints WebService Service Object and file uploads

Try something like below:

 

  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());
}

 

0 Kudos
Reply