Uploading Files Using Soa Layer
From Business Process Management, BPM and Workflow Automation Wiki | BizAgi BPMS
<keywords content="keywords"> send file, external system, upload file </keywords>
Contents |
Uploading Files Using SOA Layer
Overview
Often, it is necessary to send files from an external system into Bizagi processes (as attachments). This is achieved through Bizagi's SOA layer, by sending out the information through the SOA layer's web methods in standard XMLs.
What you need to do
To send files into Bizagi through its web services, take into account the following:
- Specify the name for the file (for an attribute of the File type in Bizagi's data model), through an XML attribute called fileName of the File element.
- Send the file's content as bytes in base-64, as the value inside the File element.
Example
The following example of a sent XML (to Bizagi) illustrates this idea:
In this case, an entity named Incident, is related to the application entity by a relation attribute called Incident as well.
This Incident entity has an attribute of File type, called MyFile.
Therefore, for this MyFile attribute, we need to include in the XML a mandatory element called File.
Sample Code
The following sample code sends an XML with an attached file, for scenarios when external systems will create a new case in Bizagi and have that case contain an uploaded file.
This XML serves as a template for sending the file in a case creation.
Below is a sample code in C#, in which a file is selected and appended to the XML. The code contains explanatory comments.
private void button2_Click(object sender, System.EventArgs er) { //Open the file to be sent if(openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { //Obtain the file’s name string file_name = openFileDialog1.FileName.Substring(openFileDialog1.FileName.LastIndexOf("\\") + 1); //Load the file into a stream Stream fileStream = openFileDialog1.OpenFile(); //The fileStream is loaded into a BinaryReader BinaryReader binaryReader = new BinaryReader(fileStream); //Read the bytes and save them in an array byte[] oBytes = binaryReader.ReadBytes(Convert.ToInt32(fileStream.Length)); //Load an empty StringBuilder into an XmlWriter System.Text.StringBuilder sb = new System.Text.StringBuilder(); TextWriter tw = new StringWriter(sb); XmlTextWriter m_XmlWriter = new XmlTextWriter(tw); //Transform the bytes in the StringBuilder into Base64 m_XmlWriter.WriteBase64(oBytes, 0, oBytes.Length); //Obtain (or generate) the XML to be sent to SOA XmlDocument xml = new XmlDocument(); xml.Load(@"D:\dv\testXmls\createCases1.xml"); //Create the element with the same name as the attribute of File type in Bizagi, and the fileName attribute of the XML XmlElement newElement = xml.CreateElement("File"); XmlAttribute newAttribute = xml.CreateAttribute("fileName"); newAttribute.Value = file_name; newElement.Attributes.Append(newAttribute); //Add the file content to the XML newElement.InnerXml = sb.ToString(); XmlNode refNode = xml.SelectSingleNode("/BizAgiWSParam/Cases/Case/Entities/Incident/MyFile"); refNode.AppendChild(newElement); //Invoke Bizagi’s SOA Layer wfsoa.WorkflowEngineSOA wf = new WorkflowEngineSOA(); XmlNode resp = wf.createCases(xml); textBox1.Text = resp.OuterXml; binaryReader.Close(); fileStream.Close(); m_XmlWriter.Close(); } }
<comments />