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
相关推荐
安得权13 小时前
.NET 把文件上传到Sharepoint - Microsoft Graph API方式
microsoft·.net·sharepoint
薛勇15 小时前
.net中如何选择async/await 和Task.Run?
c#·.net
温暖的苹果17 小时前
【.Net runtime】coreclr(.Net应用启动过程)
c#·.net·.netcore
我是唐青枫19 小时前
深入理解 C#.NET IEnumerable<T>:一切集合的起点
c#·.net
mudtools19 小时前
当传统工单遇见飞书:.NET系统的协作升级之旅
c#·自动化·.net·飞书
唐青枫19 小时前
深入理解 C#.NET Interlocked.Increment:原子操作的核心
c#·.net
AI题库1 天前
1.3 ABP MVC开发环境搭建指南:从零开始快速上手
asp.net·mvc·.net·.netcore
零点零一2 天前
Vs2022不能对xUnit建立.net framework的测试项目,可以安装模板
.net
许泽宇的技术分享2 天前
当AI开始“画“界面:A2UI协议如何让.NET应用告别写死的UI
人工智能·ui·.net·blazor·a2ui
玩泥巴的2 天前
如何在.NET系统中快速集成飞书任务分配能力
c#·.net·二次开发·飞书