TLS Settings & Auth Token
====================== NOTE ON WORKING OF EWBSession AND IT'S DEFAULT PARAMATERS ============================================
EWBSession object has two main settings objects EwbApiSetting and EwbApiLoginDetails, and some more public properties
Default constructor of EWBSession uses json config files to store EwbApiSeting and EwbApiLoginDetails.
EWBSession constructor has 2 paramaters viz.LoadAPISettingsFromConfigFile and LoadAPILoginDetailsFromConfigFile with default value as True.
Thus paramaterless constructor below assums that ASP wants to use config file to store EwbApiSetting and EWBApiLoginDetails
in default case, the TaxProEWB.API library will take case of storing AuthToken and Expiary of authtoken internally in json config file.
Getting AuthToken if null or expired and storing in EwbApiLoginDetails is concealed calls handled by library.
In case ASP needs to change store for EwbApiSetting and EwbApiLoginDetails, pleae refer to "Handling Multiple Taxpayers" section of eWay Bill API Users Guide
Also, this demo project contains complete code showing how to create TaxPayer specific EWBSession object using TaxPayer Dependency Injection.
--------------------------------------------------------------------CODE TO BEWRITTEN ON FORM LOADING ----------------------------------------------------------------------------
To avoid TLS 1.2 Connection error, write provided below code As per .Net version while loading the project initially.
for .Net framework 4.6 and above TLS1.2 is already supported
for .Net framework 4.5
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
for .Net framework 4.0
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
//this code is to display ApiLoginDetails when event refresh auth token get completed
EwbSession.RefreshAuthTokenCompleted += RefreshLoginDetailsDisplay; //(display login detail)
---------------------------------------------------------------------------------------------------------------------------------------------------------------
EWBAPI is the public static class which consist all API methods of e-Way Bill
Function call for Get Auth Token
public EWBSession EwbSession = new EWBSession();
TxnRespWithObjAndInfo<EWBSession> TxnResp = await EWBAPI.GetAuthTokenAsync(EwbSession);
//// Below is the code to call Api Synchroniously
//TxnRespWithObjAndInfo<EWBSession> TxnResp = Task.Run(() => EWBAPI.GetAuthTokenAsync(EwbSession)).Result;
if (TxnResp.IsSuccess)
{
//Call Refresh Display Api Login Details to refresh auth token and Exp Time in display
DisplayApiLoginDetails(EwbSession.EwbApiLoginDetails.IRP);
}