【Azure 应用服务】Azure App Service(Windows)环境中如何让.NET应用调用SAP NetWeaver RFC函数

简介: 【Azure 应用服务】Azure App Service(Windows)环境中如何让.NET应用调用SAP NetWeaver RFC函数

问题描述

在Azure App Service for Windows的环境中,部署.NET应用,其中使用了 SAP NetWeaver RFC函数 (需要加载 sapnwrfc.dll)。详细的错误为:

“System.DllNotFoundException: Unable to load DLL 'sapnwrfc' or one of its dependencies: The specified module could not be found. (0x8007007E)”

那么在App Service中如何来解决这个问题呢?

 

问题解答

在App Service的日志中,除了可见”System.DllNotFoundException: Unable to load DLL 'sapnwrfc' or one of its dependencies: The specified module could not be found“外,也显示 Could not open the ICU common library。如下图:

 

在App Service不能加载ICU通用库的提示下,就需要在代码中显示的加载ICU库。所以在代码中添加 NativeLibrary.Load(path.Combinee(rootDir, "nwrfcsdk", "icuin50")) 即可缓解问题。

代码示例为:

using System.Reflection;
using System.Runtime.InteropServices;
using NwRfcNet;
namespace CallSAPonAppService
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var builder = WebApplication.CreateBuilder(args);
            // Add services to the container.
            builder.Services.AddControllers();
            // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
            builder.Services.AddEndpointsApiExplorer();
            builder.Services.AddSwaggerGen();
            var app = builder.Build();
            // Configure the HTTP request pipeline.
            if (app.Environment.IsDevelopment())
            {
                app.UseSwagger();
                app.UseSwaggerUI();
            }
            app.UseHttpsRedirection();
            app.UseAuthorization();
            app.MapControllers();
            NativeLibrary.SetDllImportResolver(
                assembly: typeof(RfcConnection).Assembly,
                resolver: (string libraryName, Assembly assembly, DllImportSearchPath? searchPath) =>
                {
                    if (libraryName == "sapnwrfc")
                    {
                        var rootDir = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                        string path = Path.Combine(rootDir, "nwrfcsdk", libraryName);
                        //手动加载ICU库
                        NativeLibrary.Load(path.Combinee(rootDir, "nwrfcsdk", "icuuc50"));
                        NativeLibrary.Load(path.Combinee(rootDir, "nwrfcsdk", "icudt50"));
                        NativeLibrary.Load(path.Combinee(rootDir, "nwrfcsdk", "icuin50"));
                        NativeLibrary.TryLoad(
                            libraryPath: path,
                            handle: out IntPtr handle);
                        return handle;
                    }
                    return IntPtr.Zero;
                });
            app.Run();
        }
    }
}

 

附录一:在App Service Kudu(高级管理工具页面)如何来查看某个依赖是否存在?

如查看是否安装Visual C++ 2013 Redistributable依赖,可以使用如下命令:

reg query "HKLM\SOFTWARE\Classes\Installer\Dependencies\{61087a79-ac85-455c-934d-1fa22cc64f36}"

查看结果如图

 

 

 

参考资料

SapConnection connect issues #5 : https://github.com/huysentruitw/SapNwRfc/issues/5

 

SAP NetWeaver RFC library : https://github.com/huysentruitw/SapNwRfc#prerequisites

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.

相关文章
|
5月前
|
Ubuntu API C++
C++标准库、Windows API及Ubuntu API的综合应用
总之,C++标准库、Windows API和Ubuntu API的综合应用是一项挑战性较大的任务,需要开发者具备跨平台编程的深入知识和丰富经验。通过合理的架构设计和有效的工具选择,可以在不同的操作系统平台上高效地开发和部署应用程序。
236 11
|
安全 Windows
【Azure Cloud Service】在Windows系统中抓取网络包 ( 不需要另外安全抓包工具)
通常,在生产环境中,为了保证系统环境的安全和纯粹,是不建议安装其它软件或排查工具(如果可以安装,也是需要走审批流程)。 本文将介绍一种,不用安装Wireshark / tcpdump 等工具,使用Windows系统自带的 netsh trace 命令来获取网络包的步骤
372 32
|
安全 前端开发 Windows
Windows Electron 应用更新的原理是什么?揭秘 NsisUpdater
本文介绍了 Electron 应用在 Windows 中的更新原理,重点分析了 `NsisUpdater` 类的实现。该类利用 NSIS 脚本,通过初始化、检查更新、下载更新、验证签名和安装更新等步骤,确保应用的更新过程安全可靠。核心功能包括差异下载、签名验证和管理员权限处理,确保更新高效且安全。
456 4
Windows Electron 应用更新的原理是什么?揭秘 NsisUpdater
|
弹性计算 开发框架 安全
基于云效 Windows 构建环境和 Nuget 制品仓库进行 .Net 应用开发
本文将基于云效 Flow 流水线 Windows 构建环境和云效 Packages Nuget 制品仓库手把手教你如何开发并部署一个 .NET 应用,从环境搭建到实战应用发布的详细教程,帮助你掌握 .NET 开发的核心技能。
|
C# Windows
【Azure App Service】在App Service for Windows上验证能占用的内存最大值
根据以上测验,当使用App Service内存没有达到预期的值,且应用异常日志出现OutOfMemory时,就需要检查Platform的设置是否位64bit。
291 11
|
安全 算法 编译器
.NET 9 AOT的突破 - 支持老旧Win7与XP环境
【10月更文挑战第30天】在.NET 9 中,AOT(Ahead-of-Time)编译技术在支持老旧的 Windows 7 和 XP 系统方面取得了显著进展。主要突破包括:性能提升(启动速度加快、执行效率提高)、部署优化(无需安装.NET 运行时、减小应用程序体积)、兼容性保障(编译策略优化、依赖项管理改进)以及安全性增强(代码保护机制)。这些改进使得应用程序在老旧系统上运行更加流畅、高效和安全。
596 2
|
XML 安全 API
.NET 9 AOT的突破 - 支持老旧Win7与XP环境
.NET 9开始,AOT支持Win7和XP,不仅仅只支持SP1版本
.NET 9 AOT的突破 - 支持老旧Win7与XP环境
|
XML 缓存 前端开发
Electron-builder 是如何打包 Windows 应用的?
本文首发于微信公众号“前端徐徐”,作者徐徐深入解析了 electron-builder 在 Windows 平台上的打包流程。文章详细介绍了 `winPackager.ts`、`AppxTarget.ts`、`MsiTarget.ts` 和 `NsisTarget.ts` 等核心文件,涵盖了目标创建、图标处理、代码签名、资源编辑、应用签名、性能优化等内容,并分别讲解了 AppX/MSIX、MSI 和 NSIS 安装程序的生成过程。通过这些内容,读者可以更好地理解和使用 electron-builder 进行 Windows 应用的打包和发布。
1063 0
|
数据可视化 程序员 C#
C#中windows应用窗体程序的输入输出方法实例
C#中windows应用窗体程序的输入输出方法实例
343 0
SAP MM/FI_运费处理方式
常见的采购运费处理方式