SapNwRfc 适用于 .NET 5 .NET Core 和 .NET Framework 的 SAP NetWeaver RFC 库

SAP NetWeaver RFC library

This cross-platform library allows you to call SAP NetWeaver RFC functions from .NET 5, .NET Core and the .NET Framework.

The library is fully tested and production ready. Supported operating systems are Windows, Linux and macOS.

Also supports connection pooling for more complex applications, see below.

Get it on NuGet

dotnet add package SapNwRfc

or

PM> Install-Package SapNwRfc

Prerequisites

This library requires the SAP NetWeaver RFC Library 7.50 SDK C++ binaries that should be installed locally. For download and installation instructions see SAP Note 2573790.

You can either place the DLL's in your project output folder or put them in a folder available in the systems PATH (Windows), LD_LIBRARY_PATH (Linux) or DYLD_LIBRARY_PATH (macOS) environment variable.

On Windows, the 7.50 version of the SAP binaries also require you to install the 64-bit version of the Visual C++ 2013 Redistributable package which can be downloaded and installed from here.

MacOSX and DYLD_LIBRARY_PATH

When your application is started as a child-process (f.e. when running it using Visual Studio for Mac), it is possible that the DYLD_LIBRARY_PATH is not forwarded to the child-process. This is because of this runtime protection Apple has added to OSX.

The simplest solution to this problem is to make sure the SAP binaries are placed in the working directory of your application.

or to use the NativeLibrary.SetDllImportResolver method in your application.

A more flexible workaround is to set the import resolver for the SapLibrary using the SetDllImportResolver-method like this:

cs 复制代码
NativeLibrary.SetDllImportResolver(
    assembly: typeof(SapLibrary).Assembly,
    resolver: (string libraryName, Assembly assembly, DllImportSearchPath? searchPath) =>
    {
        if (libraryName == "sapnwrfc")
        {
            NativeLibrary.TryLoad(
                libraryPath: Path.Combine("<your_sap_rfc_binaries_path>", libraryName),
                handle: out IntPtr handle);

            return handle;
        }

        return IntPtr.Zero;
    });

Call function with input parameters but no output parameters

cs 复制代码
class SomeFunctionParameters
{
    [SapName("SOME_FIELD")]
    public string SomeField { get; set; }
}

using var someFunction = connection.CreateFunction("BAPI_SOME_FUNCTION_NAME");
someFunction.Invoke(new SomeFunctionParameters
{
    SomeField = "Some value",
});

Call function with input and output parameters

cs 复制代码
class SomeFunctionParameters
{
    [SapName("SOME_FIELD")]
    public string SomeField { get; set; }
}

class SomeFunctionResult
{
    [SapName("RES_ABC")]
    public string Abc { get; set; }
}

using var someFunction = connection.CreateFunction("BAPI_SOME_FUNCTION_NAME");
var result = someFunction.Invoke<SomeFunctionResult>(new SomeFunctionParameters
{
    SomeField = "Some value",
});

// Do something with result.Abc
相关推荐
一只小灿灿14 小时前
VB.NET在 Excel 二次开发中的全面应用
.net·excel
码农君莫笑14 小时前
信管通低代码信息管理系统应用平台
linux·数据库·windows·低代码·c#·.net·visual studio
liyongqiangcc21 小时前
了解 ASP.NET Core 中的中间件
.net
Kiros_Jiang1 天前
开源低代码平台-Microi吾码 打印引擎使用
javascript·开源·json·.net·pip
码农君莫笑1 天前
Blazor项目中使用EF读写 SQLite 数据库
linux·数据库·sqlite·c#·.netcore·人机交互·visual studio
web147862107231 天前
C# .Net Web 路由相关配置
前端·c#·.net
_oP_i1 天前
.NET Core 项目配置到 Jenkins
运维·jenkins·.netcore
数据的世界012 天前
.NET开发人员学习书籍推荐
学习·.net
paixiaoxin2 天前
CV-OCR经典论文解读|An Empirical Study of Scaling Law for OCR/OCR 缩放定律的实证研究
人工智能·深度学习·机器学习·生成对抗网络·计算机视觉·ocr·.net