huysentruitw / SapNwRfc

SAP NetWeaver RFC library for .NET 5, .NET Core and .NET Framework
MIT License
149 stars 43 forks source link

"Type 'System.String' does not have a default constructor (Parameter 'type')" #103

Closed GustavoDamasceno closed 3 months ago

GustavoDamasceno commented 3 months ago

I am trying to send data to a table from an RFC. Here is the table structure:

image image

To send the data, I am creating this algorithm:


var parameters = new SapFuncionParameters
{
    table = new[]
    {
        new ZSDS_EASYP_MSG
        {
            message = mensagem
        }
    }
};

string connectionString = sapConfig.SapconnectionString(ConfigurationManager.AppSettings["Ambiente"].ToString());
using var connection = new SapConnection(connectionString);

try
{
    connection.Connect();

    using var someFunction = connection.CreateFunction("ZRFC_EASY_PALLET_04");
    var result = someFunction.Invoke<string>(new SapFuncionParameters
    {
        table = parameters.table
    });

    Console.WriteLine("Log salvo no SAP com sucesso.");

}
catch (Exception ex)
{

    throw ex;
}

And since it is a table structure, I created the following classes for the parameter I want to send to SAP.


public class SapFuncionParameters
{
    [SapName("T_MESSAGE")]
    public ZSDS_EASYP_MSG[] table { get; set; }
}

public class ZSDS_EASYP_MSG
{
    [SapName("MESSAGE")]
    public string message { get; set; }
}

However, I am not successful. I have tried converting it to a list instead of an array, but without success.

In the old SAP NCO with .NET Framework support, I used to do it like this:


RfcDestination dest = GetRepository("ITGViagem");
RfcRepository repo = dest.Repository;
IRfcFunction fReadTable = repo.CreateFunction("ZRFC_EASY_PALLET_04");
var dtImportCli = fReadTable.GetTable("T_MESSAGE");
dtImportCli.Append();

 //dtImportCli.Append();
id = id.PadLeft(10, '0'); ;
msg = msg;

string mensagem = id + " | " + msg;
dtImportCli.SetValue("MESSAGE", mensagem);

fReadTable.SetValue("T_MESSAGE", dtImportCli);
fReadTable.Invoke(dest);

Is it possible to do the same for SAP NWRFC?

tom-j-irvine commented 3 months ago

It looks like you are asking it to respond with a string:

image

If you don't require a response, you would invoke the function like this: https://github.com/huysentruitw/SapNwRfc?tab=readme-ov-file#call-function-with-input-parameters-but-no-output-parameters

Otherwise, you need to give it an appropriate class for the output.

GustavoDamasceno commented 3 months ago

Thanks