viernes, 24 de enero de 2014

Consumir servicio web TRM para Colombia - Banco de la República

En la página http://www.banrep.gov.co/es/trm se encuentra diariamente la TRM, referencia para diferentes movimientos comerciales en moneda USD. A continuación, un ejemplo de como consumir el servicio web público del Banco para obtener la TRM desde un programa, en este caso en C#.

El primer paso es agregar la referencia web al proyecto en Visual. En este caso específico es: http://obiee.banrep.gov.co/analytics/saw.dll?wsdl

Luego viene el código para leer el reporte específico:

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Data.SqlClient;
using System.Configuration;
using TRM_BanRep.banrep;
using System.Data;

namespace TRM_BanRep
{
 class Program
    {
        /// 
        /// Based on Obiee Web Services – Using .net and C# post on http://tipsonobiee.blogspot.com/2009/07/obiee-web-services-using-net-and-c.html
        /// 
        /// 
        static void Main(string[] args)
        {
   //Open SAW session in OracleBI - Banco de la Republica
   SAWSessionServiceSoapClient sawSession = new SAWSessionServiceSoapClient();
   string sessionID = sawSession.logon("publico", "publico");
   
   //Set report parameters
   ReportRef repRef = new ReportRef();
   //path: get from report http url
   repRef.reportPath = @"/shared/Consulta Series Estadisticas desde Excel/1. Tasa de Cambio Peso Colombiano"
    + "/1.1 TRM - Disponible desde el 27 de noviembre de 1991/TRM para un dia";
   //xml: get from report http url + &format=xml
   repRef.reportXml = ""
    + ""
    + ""
    + "";

   //Create xml view, set xml options
   XmlViewServiceSoapClient xmlView = new XmlViewServiceSoapClient();
   XMLQueryExecutionOptions xmlOpts = new XMLQueryExecutionOptions();
   xmlOpts.maxRowsPerPage = 100;
   xmlOpts.refresh = true;

   //Pass report parameters
   ReportParams repParams = new ReportParams();

   //Execute XML Query
   QueryResults qResults = xmlView.executeXMLQuery(repRef, XMLQueryOutputFormat.SAWRowsetData, xmlOpts, repParams, sessionID);

   //Print rowset
   sawSession.logoff(sessionID);

   //Get rate value from result XML
   XmlDocument results = new XmlDocument();
   results.LoadXml(qResults.rowset);

   DateTime trmDate = DateTime.Today.AddDays(-5);
   XmlNodeList xnlDate = results.GetElementsByTagName("Column0");
   foreach (XmlNode xn in xnlDate)
    trmDate = DateTime.ParseExact(xn.InnerText, "dddd d 'de' MMMM 'de' yyyy", CultureInfo.CreateSpecificCulture("es-CO"));

   decimal trm = decimal.Zero;
   XmlNodeList xnlRate = results.GetElementsByTagName("Column2");
   foreach (XmlNode xn in xnlRate)
    trm = Convert.ToDecimal(xn.InnerText, CultureInfo.InvariantCulture);

        }
    }
}


Nota: La URL del reporte mencionada en los comentarios se obtiene del código fuente de la página.

viernes, 20 de abril de 2012

BPM - Error invoking .NET method

When creating a new Action for a Method Directive, there's an option called synchronously invoke .NET method don't queue record nothing. Basically, a user generated dll's method must be selected in the method option. But first, the method dll must be copied into the Epicor Software\BPMServer\Actions folder on server and the BPM service must be restarted.


It may happen that after selecting the method in the .NET Action proxy builder, an error raises:


"Error retrieving action list from the server: Could not load file or assembly 'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=...' or one of its dependencies."

The explanation seems to be that the custom project in Visual Studio must be built for the right .NET Framework version. In my case (Epicor 9 - version 9.05.604A) it was Framework 3.5. After rebuilding, everything worked fine.