【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.

相关文章
|
2月前
|
存储 安全 Linux
【Azure App Service】在App Service中查看CA证书
在 Azure App Service 中,使用自签名或私有 CA 证书的远程服务可能会导致 SSL 握手失败。解决方法包括使用受信任 CA 签发的证书,或通过 App Service Environment 加载自定义根证书,实现安全连接。
|
1月前
|
API 网络架构 容器
【Azure Container App】查看当前 Container App Environment 中的 CPU 使用情况的API
在扩展 Azure Container Apps 副本时,因 Container App Environment 的 CPU 核心数已达上限(500 cores),导致扩展失败。本文介绍如何使用 `az rest` 命令调用 Azure China Cloud 管理 API,查询当前环境的 CPU 使用情况,并提供具体操作步骤及示例。
91 16
|
21天前
|
数据安全/隐私保护
【Azure Function App】PowerShell Function 执行 Get-AzAccessToken 的返回值类型问题:System.String 与 System.Security.SecureString
将PowerShell Function部署到Azure Function App后,Get-AzAccessToken返回值类型在不同环境中有差异。正常为SecureString类型,但部分情况下为System.String类型,导致后续处理出错。解决方法是在profile.ps1中设置环境变量$env:AZUREPS_OUTPUT_PLAINTEXT_AZACCESSTOKEN=false,以禁用明文输出。
|
3月前
|
存储 缓存 Serverless
【Azure Container App】如何在Consumption类型的容器应用环境中缓存Docker镜像
在 Azure 容器应用的 Consumption 模式下,容器每次启动均需重新拉取镜像,导致冷启动延迟。本文分析该机制,并提出优化方案:使用 ACR 区域复制加速镜像拉取、优化镜像体积、设置最小副本数减少冷启动频率,或切换至 Dedicated 模式实现镜像缓存,以提升容器启动效率和应用响应速度。
|
16天前
|
运维 安全 网络安全
Windows Server 2019拨号“找不到设备”?Error 1058解决指南
Windows Server 2019拨号报错1058?别急!这不是硬件故障,而是关键服务被禁用。通过“服务依存关系”排查,依次启动“安全套接字隧道协议”“远程接入连接管理”和“路由与远程访问”服务,仅需4步即可恢复PPPoE或VPN拨号功能,轻松解决网络中断问题。
96 1
|
16天前
|
存储 SQL 人工智能
Windows Server 2025 中文版、英文版下载 (2025 年 9 月更新)
Windows Server 2025 中文版、英文版下载 (2025 年 9 月更新)
502 3
Windows Server 2025 中文版、英文版下载 (2025 年 9 月更新)
|
19天前
|
安全 Unix 物联网
Windows 7 & Windows Server 2008 R2 简体中文版下载 (2025 年 9 月更新)
Windows 7 & Windows Server 2008 R2 简体中文版下载 (2025 年 9 月更新)
170 2
|
5月前
|
安全 数据安全/隐私保护 虚拟化
Windows Server 2022 中文版、英文版下载 (2025 年 5 月更新)
Windows Server 2022 中文版、英文版下载 (2025 年 5 月更新)
789 2
|
13天前
|
安全 Linux iOS开发
SonarQube Server 2025 Release 5 (macOS, Linux, Windows) - 代码质量、安全与静态分析工具
SonarQube Server 2025 Release 5 (macOS, Linux, Windows) - 代码质量、安全与静态分析工具
86 0
SonarQube Server 2025 Release 5 (macOS, Linux, Windows) - 代码质量、安全与静态分析工具

热门文章

最新文章