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
相关推荐
追逐时光者8 小时前
.NET 使用 MethodTimer 进行运行耗时统计提升代码的整洁性与可维护性!
后端·.net
许泽宇的技术分享15 小时前
Windows桌面自动化的革命性突破:深度解析Windows-MCP.Net Desktop模块的技术奥秘
windows·自动化·.net
追逐时光者1 天前
C#/.NET/.NET Core技术前沿周刊 | 第 50 期(2025年8.11-8.17)
后端·.net
csdn_aspnet2 天前
ASP.NET Core 中的多租户 SaaS 应用程序
.netcore·saas
唐青枫2 天前
别滥用 Task.Run:C# 异步并发实操指南
c#·.net
zzzhpzhpzzz3 天前
Win10快速安装.NET3.5
.net·win10
许泽宇的技术分享3 天前
Windows MCP.Net:基于.NET的Windows桌面自动化MCP服务器深度解析
windows·自动化·.net
百锦再3 天前
.NET 的 WebApi 项目必要可配置项都有哪些?
java·开发语言·c#·.net·core·net
hqwest3 天前
C#WPF实战出真汁06--【系统设置】--餐桌类型设置
c#·.net·wpf·布局·分页·命令·viewmodel
做一位快乐的码农4 天前
基于.net、C#、asp.net、vs的保护大自然网站的设计与实现
c#·asp.net·.net