SAP .NET Connector (SAPNCO) & .Net Core
Asked Answered
V

5

7

The SAP .NET Connector is not compatible with the .NET Core framework. Is there any other way to retrieve data from SAP when using .NET Core?

I've already searched for an alternative in the nuget package manager but I did not found one. Is there any workaround I can use?

I would very much like to benefit from the performance of .NET Core but I also need to be able to connect to SAP.

Vickey answered 3/4, 2018 at 9:46 Comment(1)
As a workaround, you can create your own nuget package containing the Sap.Data.Hana.v4.5.dll file, as hinted at here: #41499042 Dotnet Build will complain about the framework mismatch, but it will work (at least on Windows).Holding
W
4

For making calls from a .NET Core or .NET Framework application, I've open-sourced a cross-platform library SapNwRfc.

Get it on NuGet:

dotnet add package SapNwRfc

or

PM> Install-Package SapNwRfc

Strengths:

  • Cross-platform: Windows / Linux / macOS
  • Maps input and output models by convention (zero configuration)
  • Mapping functions are generated on-the-fly using expression trees
  • Connection pooling with retry support, DI friendly
  • Allows test driven development by the means of simple mockable interfaces
  • Licensed under MIT

The library is fully unit-tested and production ready.

Example

string connectionString = "AppServerHost=MY_SERVER_HOST; SystemNumber=00; User=MY_SAP_USER; Password=SECRET; Client=100; Language=EN; PoolSize=5; Trace=8";

using var connection = new SapConnection(connectionString);
connection.Connect();

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",
});

For more details, see the README.

Wayfaring answered 1/4, 2020 at 14:0 Comment(0)
S
1

​I have created a library to easly making SAP RFC calls from .NET CORE Libray is supported in Windows, Linux and macOS. Check it solves your needs https://github.com/nunomaia/NwRfcNet/

Steffie answered 19/9, 2019 at 22:44 Comment(0)
A
1

I don't know if this is still relevant for you, but maybe for others who come here via web search.

SAP finally released their .NET Connector also for .NET 8.
See the updated note SAP NCo 3.1 release and support strategy.

Akkerman answered 1/8 at 7:27 Comment(4)
that's great to know, have you used it in .net 8?Unstrained
Yes. Nothing spectacular, but it works.Akkerman
I have personally tried to connect it with .net and I have not been able to. I always get the exceptions: System.TypeInitializationException: 'The type initializer for 'SAP.Middleware.Connector.RfcConfigParameters' threw an exception.' FileNotFoundException: 'Failed to load file or assembly 'System.ServiceModel, Version=4.0.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the specified fileUnstrained
I am not an expert here, but Version=4.0.0.0.0 does not sound as if you started your application with .NET 8. Did you read installation.txt which came with the NCo .NET Core zip file?Akkerman
F
0

I accept that you have an SOAP based Service on SAP side and you try to connect this SAP service via .NetCore. If this senerio is true, unfortunetelly you can not connect SOAP service with .NetCore via "Add Service Reference." But you can search about ".NetCore Wcf Client Service".

Another solution is that use Rest Service and simulate SOAP protocol.

Here is the sample problem and solution at there.

Client to send SOAP request and received response

Fetich answered 4/4, 2018 at 7:5 Comment(1)
Actually I make use of nuget package nuget.org/packages/sapnco3.x64 in my projects(.net Framework 4.5). Now I've created a test application in .NET Core and it seems I cannot use the package cause it is not compatible with .NET core. I am wondering if there is any other nuget package I can use to connect to SAP (via RFC, not via SOAP) ...Vickey
A
-1

Besides the great work of huysentruitw, I would also like to mention our library:

dbosoft YaNco (Yet another .NET connector): https://github.com/dbosoft/YaNco


Highlights:

  • cross platform
  • DI / Unit testing friendly
  • based on functional programming (using Language.Ext)
  • ABAP callbacks support
  • commercial support / consulting services available from dbosoft.eu

License: MIT

.NET Versions: .NET 4.7.1 and higher, .NET Core 2.0 and higher, NET 5.0

Supported platforms: Windows, Linux and MacOS

Nuget: Dbosoft.YaNco


Instead of mapping from / to POCOs YaNco uses functions to map input/output of SAP RFC RFMs. This gives you a lot of flexibility in how you can map your data.

Example:

       await context.CallFunction("BAPI_COMPANYCODE_GETLIST",
                Output: f => f
                    .MapTable("COMPANYCODE_LIST", s =>
                        from code in s.GetField<string>("COMP_CODE")
                        from name in s.GetField<string>("COMP_NAME")
                        select (code, name)))
            .Match(
                r =>
                {
                    foreach (var (code, name) in r)
                    {
                        Console.WriteLine($"{code}\t{name}");
                    }
                },
                l => Console.WriteLine($"Error: {l.Message}"));
Antipasto answered 3/5, 2021 at 20:57 Comment(1)
The library needs better documentation and examples.Bronchia

© 2022 - 2024 — McMap. All rights reserved.