Get Bench Mark Interest Rates
1. getBenchMarkInterestRates.cs
These four packages are required to be used.
Step 1. Create class file to store content of the web response.
2. getBenchMarkInterestRates.aspx.cs
These 15 packages are required to be used.
Step 1. Create URL which will be post to the server. User inputs need to be stored in the class created, and serialize into JSON format. In this function, only header is needed.
Step 2. Post to the server, and store response. URL is sent using web request function, and a response will be send back from the server. The response need to be deserialized into the ‘getBenchMarkInterestRates’ class.
Step 3. Obtain error code. If error code is ‘010000’ which means invocation successful, populate attributes of the ‘getBenchMarkInterestRates’ class into the Grid View. Else, we will display the ErrorText and ErrorDetails.
Overview of getBenchMarkInterestRates.cs
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Demo
{
public class getBenchmarkInterestRatesRootObject
{
public getBenchmarkInterestRatesContent Content { get; set; }
}
public class getBenchmarkInterestRatesContent
{
public getBenchmarkInterestRatesServiceResponse ServiceResponse { get; set; }
}
public class getBenchmarkInterestRatesServiceResponse
{
public getBenchmarkInterestRatesInterestRateList InterestRateList { get; set; }
public getBenchmarkInterestRatesServiceRespHeader ServiceRespHeader { get; set; }
}
public class getBenchmarkInterestRatesServiceRespHeader
{
public string ErrorText { get; set; }
public object ErrorDetails { get; set; }
public string GlobalErrorID { get; set; }
}
public class getBenchmarkInterestRatesInterestRateItem
{
public string interestRate { get; set; }
public string country { get; set; }
public string period { get; set; }
public string currency { get; set; }
}
public class getBenchmarkInterestRatesInterestRateList
{
[JsonConverter(typeof(ArrayConverter<getBenchmarkInterestRatesInterestRateItem>))]
public List<getBenchmarkInterestRatesInterestRateItem> InterestRateItem { get; set; }
}
}
Overview of getBenchMarkInterestRates.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DotNetOpenAuth.OAuth2;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Collections.Specialized;
using System.Configuration;
using System.Net;
using System.IO;
using System.Windows.Forms;
using System.Data;
namespace Demo
{
public partial class GetBenchmarkInterestRates : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSend_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
gvGetBenchMarkInterestRates.DataSource = null;
gvGetBenchMarkInterestRates.DataBind();
try
{
var header = new HeaderJson();
header.userID = "";
header.PIN = "";
header.serviceName = "getBenchmarkInterestRates";
header.OTP = "";
var headerJson = new HeaderJsonObject();
headerJson.Header = header;
string strHeader = JsonConvert.SerializeObject(headerJson);
string url = "http://tbankonline.com/SMUtBank_API/Gateway?Header=" + strHeader;
var webRequest = (HttpWebRequest)WebRequest.Create(url);
webRequest.ContentType = "application/json";
webRequest.Method = "POST";
var result = "";
var httpResponse = (HttpWebResponse)webRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
result = streamReader.ReadToEnd();
}
getBenchmarkInterestRatesRootObject interest = new getBenchmarkInterestRatesRootObject();
interest = JsonConvert.DeserializeObject<getBenchmarkInterestRatesRootObject>(result);
string globalErrorID = interest.Content.ServiceResponse.ServiceRespHeader.GlobalErrorID.ToString();
if (globalErrorID == "010000")
{
int counter = interest.Content.ServiceResponse.InterestRateList.InterestRateItem.Count();
DataTable dt = new DataTable();
DataColumn col1 = new DataColumn(" ", typeof(string));
DataColumn col2 = new DataColumn("Interest Rate", typeof(string));
DataColumn col3 = new DataColumn("Country", typeof(string));
DataColumn col4 = new DataColumn("Period Rate", typeof(string));
DataColumn col5 = new DataColumn("Currency", typeof(string));
dt.Columns.Add(col1);
dt.Columns.Add(col2);
dt.Columns.Add(col3);
dt.Columns.Add(col4);
dt.Columns.Add(col5);
// put data into the data table
for (int i = 0; i <= counter - 1; i++)
{
DataRow row = dt.NewRow();
dt.Rows.Add(row);
dt.Rows[i][col1] = i + 1;
dt.Rows[i][col2] = interest.Content.ServiceResponse.InterestRateList.InterestRateItem[i].interestRate?.ToString() ??" ";
dt.Rows[i][col3] = interest.Content.ServiceResponse.InterestRateList.InterestRateItem[i].country?.ToString() ?? " ";
dt.Rows[i][col4] = interest.Content.ServiceResponse.InterestRateList.InterestRateItem[i].period?.ToString() ?? " ";
dt.Rows[i][col5] = interest.Content.ServiceResponse.InterestRateList.InterestRateItem[i].currency?.ToString() ?? " ";
}
gvGetBenchMarkInterestRates.DataSource = dt;
gvGetBenchMarkInterestRates.DataBind();
}
else
{
lblTest.Text = interest.Content.ServiceResponse.ServiceRespHeader.ErrorText.ToString();
string errorMessage = interest.Content.ServiceResponse.ServiceRespHeader.ErrorDetails.ToString();
lblErrorMessage.Text = errorMessage;
}
}
catch (Exception ex)
{
lblExceptionMsg.Text = ex.ToString();
}
}
}
}
}
Created with the Personal Edition of HelpNDoc: Free Web Help generator