Subir Archivos Usando la Capa SOA
De
<keywords content="keywords"> enviar archivo, sistema externo, subir archivo </keywords>
Contenido |
Subir Archivos Usando la Capa SOA
Introducción
Con frecuencia es necesario enviar archivos desde un sistema externo hacia los procesos en Bizagi, y esto se puede realizar usando la Capa SOA de Bizagi.
Por medio de los servicios web que ofrece la Capa SOA, dicha información de los archivos se pueden enviar a través de XMLs.
Qué debe hacerse
Para subir archivos a los procesos Bizagi desde un sistema externo por medio de la Capa SOA, se debe tener en cuenta lo siguiente:
- Especifique el nombre que tomará el archivo (atributo en el modelo de datos de Bizagi de tipo de Archivo), en un atributo XML llamado fileName del elemento File.
- Envie el contenido del archivo como bytes en base-64, dentro del elemento File.
Ejemplo
El siguiente es un ejemplo del XML de envio, mostrando lo descrito anteriormente:
En este caso, una entidad llamada Incidente (Incident), es relacionada a la entidad de aplicación por el atributo Incidente (Incident).
Esta entidad tiene un atributo de tipo Archivo llamado: MiArchivo (MyFile).
Ante esto, el atributo de tipo Archivo deberá tener un elemento obligatorio "File" para la información.
Código de Muestra
Éste es una muestra de código que envia un XML a Bizagi con un archivo adjunto.
Para esta muestra, partiremos de los escenarios donde ciertos sistemas requieren crear un caso nuevo en Bizagi y adjuntarle un archivo a éste.
Este XML sirve como una plantilla para enviar el archivo.
A continuación está un código de muestra en C#, en el que se selecciona un archivo y se añade al XML. El código contiene comentarios explicativos.
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 />


