Hi Readers,
I have come across a situation where I was in need of sending the image of a worker to the third party application through web services.
So, I have written a method in the service class which will take the HCMWorker table person field as input. This method will find the image of the worker and convert that into XML element and finally to a string and will return it to the calling method(serialization and deserialization concept). Have a look at how I achieved this.
//[SysEntryPointAttribute(true)]
public str getImageXml(DirPartyRecId _person)
{
XmlDocument xmlEnvelope;
XmlElement childNode;
str content;
BinData bin = new BinData();
System.String myCLRString;
Str myXppString;
;
//creating BinData object from Container in the CompanyImage object
bin.setData(HcmPersonImage::findByPerson(_person).Image);
//encoding the image to base64
content = bin.base64Encode();
//creating the envelope and inserting a XmlElement that contains the image into a base64 string
xmlEnvelope = new XmlDocument();
childNode = xmlEnvelope.CreateElement(“image”);
childNode.innerXml(content);
xmlEnvelope.AppendChild(childNode);
myCLRString = xmlEnvelope.xml();
myXppString = myCLRString;
return myXppString;
}
Happy New Year Folks!!!