huysentruitw / SapNwRfc

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

Add CreateFunction / GetTypeMetadata / GetFunctionMetadata to ISapServerConnection #51

Closed campersau closed 2 years ago

campersau commented 2 years ago

The connectionHandle which gets passed to RfcServerFunction can be used to call back into SAP to get metadata and call functions. I also tried to add Ping but it always returned RFC_INVALID_HANDLE.

SapServer.InstallGenericServerFunctionHandler(clientParameters, (connection, function) =>
{
    // call back into SAP to get metadata and call functions
    var functionMetadata = connection.GetFunctionMetadata("BAPI_SOME_FUNCTION_NAME");
    var typeMetadata = connection.GetTypeMetadata("MY_STRUCT");
    using (var fn = connection.CreateFunction("BAPI_SOME_FUNCTION_NAME"))
    {
        fn.Invoke();
    }

    // handle the actual server function call
    switch (function.GetName())
    {
    case "BAPI_SOME_FUNCTION_NAME":
        function.SetResult(new { RESULT = "X" });
        break;
    }
});
huysentruitw commented 2 years ago

Thanks again!