I have written a ASP.net web method in C# that takes a Parameter Customer reference before displaying the customer balance. It can be accessed via http://localhost:59294/api/Balance/getAccountBalance.aspx?CustomerReference=tk20000
The application consuming it wants the URL as http://localhost:59294/api/Balance/getAccountBalance(tk20000). How do I go about URL rewrite? Kindly assist.
[WebMethod]
public void getAccountBalance(string CustomerReference)
{
List<Customer> listEmployees = new List<Customer>();
OdbcDataReader rdr;
string cs = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (OdbcConnection con = new OdbcConnection(cs))
{
OdbcCommand cmd = new OdbcCommand();
cmd.Connection = con;
cmd.CommandType = System.Data.CommandType.Text;
string querystring = "SELECT TOP 10 " + qt + "CardCode" + qt + ", " + qt + "Balance" + qt + ", " + qt + "Currency" + qt + " FROM " + qt + "TSLHANA" + qt + "." + qt + "OCRD" + qt + "WHERE " + qt + "CardCode" + qt + "= '" + CustomerReference + "'";
cmd.CommandText = querystring;
if (con.State != ConnectionState.Open)
{
con.Close();
con.Open();
cmd.Connection = con;
rdr = cmd.ExecuteReader();
while (rdr.Read())
{
Customer customer = new Customer();
//customer.CardCode = rdr["CardCode"].ToString();
// customer.LoyaltyCustomerReference = rdr["U_LoyaltyCustomerReference"].ToString();
customer.Balance = rdr["Balance"].ToString();
// customer.Currency = rdr["Currency"].ToString();
listEmployees.Add(customer);
}
con.Close();
con.Dispose();
}
}
if (listEmployees.Count >= 1)
{
JavaScriptSerializer js = new JavaScriptSerializer();
Context.Response.Write(js.Serialize(listEmployees));
}
else
{
string dqt = "\"";
Context.Response.Write("[{" + dqt + "Error" + dqt + ":" + dqt + "No records found for customer " + CustomerReference + dqt + "}]");
}
}