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

相关文章
|
8月前
|
C# Android开发 iOS开发
2025年全面的.NET跨平台应用框架推荐
2025年全面的.NET跨平台应用框架推荐
313 23
|
9月前
|
区块链 C# Windows
PasteEx:一款.NET开源的Windows快捷粘贴神器
PasteEx:一款.NET开源的Windows快捷粘贴神器
121 17
|
9月前
|
Web App开发 C# Windows
一款.NET开源的Windows资源管理器标签页工具
一款.NET开源的Windows资源管理器标签页工具
122 5
|
10月前
|
安全 前端开发 Windows
Windows Electron 应用更新的原理是什么?揭秘 NsisUpdater
本文介绍了 Electron 应用在 Windows 中的更新原理,重点分析了 `NsisUpdater` 类的实现。该类利用 NSIS 脚本,通过初始化、检查更新、下载更新、验证签名和安装更新等步骤,确保应用的更新过程安全可靠。核心功能包括差异下载、签名验证和管理员权限处理,确保更新高效且安全。
243 4
Windows Electron 应用更新的原理是什么?揭秘 NsisUpdater
|
9月前
|
弹性计算 开发框架 安全
基于云效 Windows 构建环境和 Nuget 制品仓库进行 .Net 应用开发
本文将基于云效 Flow 流水线 Windows 构建环境和云效 Packages Nuget 制品仓库手把手教你如何开发并部署一个 .NET 应用,从环境搭建到实战应用发布的详细教程,帮助你掌握 .NET 开发的核心技能。
|
10月前
|
开发框架 监控 .NET
【Azure App Service】部署在App Service上的.NET应用内存消耗不能超过2GB的情况分析
x64 dotnet runtime is not installed on the app service by default. Since we had the app service running in x64, it was proxying the request to a 32 bit dotnet process which was throwing an OutOfMemoryException with requests >100MB. It worked on the IaaS servers because we had the x64 runtime install
160 5
|
10月前
|
JSON 算法 安全
JWT Bearer 认证在 .NET Core 中的应用
【10月更文挑战第30天】JWT(JSON Web Token)是一种开放标准,用于在各方之间安全传输信息。它由头部、载荷和签名三部分组成,用于在用户和服务器之间传递声明。JWT Bearer 认证是一种基于令牌的认证方式,客户端在请求头中包含 JWT 令牌,服务器验证令牌的有效性后授权用户访问资源。在 .NET Core 中,通过安装 `Microsoft.AspNetCore.Authentication.JwtBearer` 包并配置认证服务,可以实现 JWT Bearer 认证。具体步骤包括安装 NuGet 包、配置认证服务、启用认证中间件、生成 JWT 令牌以及在控制器中使用认证信息
365 2
|
11月前
|
XML 缓存 前端开发
Electron-builder 是如何打包 Windows 应用的?
本文首发于微信公众号“前端徐徐”,作者徐徐深入解析了 electron-builder 在 Windows 平台上的打包流程。文章详细介绍了 `winPackager.ts`、`AppxTarget.ts`、`MsiTarget.ts` 和 `NsisTarget.ts` 等核心文件,涵盖了目标创建、图标处理、代码签名、资源编辑、应用签名、性能优化等内容,并分别讲解了 AppX/MSIX、MSI 和 NSIS 安装程序的生成过程。通过这些内容,读者可以更好地理解和使用 electron-builder 进行 Windows 应用的打包和发布。
612 0
|
9月前
|
监控 前端开发 API
一款基于 .NET MVC 框架开发、功能全面的MES系统
一款基于 .NET MVC 框架开发、功能全面的MES系统
213 5
|
开发框架 前端开发 JavaScript
ASP.NET MVC 教程
ASP.NET 是一个使用 HTML、CSS、JavaScript 和服务器脚本创建网页和网站的开发框架。
193 7

热门文章

最新文章