I have the following method that calls a .NET DLL from VFP.
n=0
ON ERROR n=1
x = createobject("Business_Bancos.ApiKhipu_Bancos")
if n=0
ON error
&&respuesta=x.prueba()
respuesta=x.obtienerespuestakhipu(tipobanco, host, userNamebd, dataBase, puerto, passworddb, valor_banco, UserName, Password, EnterpriseIdentity, Role, Agreement, accountNumber, BookingDateStart, BookingDateEnd)
result=respuesta.datos
else
messagebox("Error....!!",16,"Aviso")
ENDIF
And in the .net dll, I call the method as follows:
public async Task<Respuesta> obtienerespuestakhipu(string tipobanco,
string host,
string user,
string dataBase,
string puerto,
string passworddb,
string codigobanco,
string UserName,
string Password,
string EnterpriseIdentity,
string Role,
string Agreement,
string accountNumber,
string BookingDateStart,
string BookingDateEnd)
{
string url_acount = "";
string api_key = "";
Clase_Conexion conexion = new Clase_Conexion(host, user, dataBase, puerto, passworddb);
string respuesta = "";
Respuesta resp = new Respuesta();
url_acount = await ObtieneAccountLink_BancoPersonal(api_key, UserName, Password, urlbanco_accountlink);
}
public async Task<string> ObtieneAccountLink_BancoPersonal(string api_key, string UserName, string Password, string urlbanco)
{
string accountLink = "";
var serviceCollection = new ServiceCollection();
Configuere(serviceCollection);
var servicios = serviceCollection.BuildServiceProvider();
var httpClientFactory = servicios.GetRequiredService<IHttpClientFactory>();
var client = httpClientFactory.CreateClient();
client.DefaultRequestHeaders.Add("x-api-key", api_key);
String str_json = "{\"Username\":'" + UserName + "',\"Password\":'" + Password + "'}";
JObject json = JObject.Parse(str_json);
MessageBox.Show(urlbanco);
var postData = new StringContent(json.ToString(), Encoding.UTF8, "application/json");
//se cae
var request = await client.PostAsync(urlbanco, postData);
..........
}
And following up, it falls into the following line of code:
var request = await client.PostAsync(urlbanco, postData);
When using the asynchronous method, I get an error from VFP, when calling the .NET DLL. The error it gives is the following:
An exception occurred in the log type type initializer
Does anyone have any idea how to solve it?