sifayideenjs / NwRfcNet

An easy way of making SAP RFC calls from .NET Core

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

.NET client library for SAP NetWeawer RFC

An easy way of making SAP RFC calls from .NET. Libray is supported in Windows, Linux and macOS.

Supported Platforms & Prerequisites

  • Requires .NET Framework ( .NET Standard 2.0 or higher )

    • .NET Framework 4.6.1 or higher
    • .NET Core 2.0 or higher
  • OS versions

    • Windows x64.
    • Redhat Linux 7 or other Linux distribution that is supported simultaneously by .NET Core and SAP NetWeaver RFC.
    • macOS 10.12+.
  • SAP NetWeaver RFC Library 7.50 SDK C++ binaries must be installed locally. For download and installation instructions check SAP Note 2573790

Using this package

Add the package using the dotnet cli:

$ dotnet add package NwRfcNet

Create a class to match SAP RFC parameters

    public class BapiCompanyOutputParameters
    {
        public CompanyDetails[] Details { get; set; }
    }

    public class CompanyDetails
    {
        public string CompanyCode { get; set; }

        public string Name { get; set; }
    }

Map RFC mapameters to class

    RfcMapper mapper = new RfcMapper();

    mapper.Parameter<BapiCompanyOutputParameters>().Property(x => x.Details)
        .HasParameterName("COMPANYCODE_LIST")
        .HasParameterType(RfcFieldType.Table);

    mapper.Parameter<CompanyDetails>().Property(x => x.CompanyCode)
        .HasParameterName("COMP_CODE")
        .MaxLength(4)
        .HasParameterType(RfcFieldType.Char);

    mapper.Parameter<CompanyDetails>().Property(x => x.Name)
        .HasParameterName("COMP_NAME")
        .MaxLength(25)
        .HasParameterType(RfcFieldType.Char);

Open a connection to server and invoke a BAPI

    using (var conn = new RfcConnection(userName, password, hostname, client))
    {
        conn.Open();
        using(var func = _conn.CallRfcFunction("BAPI_COMPANYCODE_GETLIST"))
        {
            func.Invoke();
        }
    }

Get result and display to Console

    var returnValue =  func.GetOutputParameters<BapiCompanyOutputParameters>();
    Console.WriteLine(String.Format("|{0,-20}|{1,-10}", "Company Code", "Company Name"));
    foreach (var row in returnValue.Details)
    {
        Console.WriteLine(String.Format("|{0,-20}|{1,-10}", row.CompanyCode, row.Name));
    }

Output should be

Company Code Company Name
C001 company 1
C002 Company 2

Samples

Included samples in project

  • List FI Companies
  • List FI Customers
  • Get Details of a FI Customer
  • FI General Ledger Account
  • RFC Read Table

Single sign-on (SSO)

Alternatively it's possible to sign-on with SSO instead of user and password.

Example : Opening a RFC connection using NTLM.

    var conn = new RfcConnection(
        hostname: "server_name", 
        client: "000", 
        sncPartnername: @"p:DOMAIN\SRVACC",
        sncLib: @"gx64ntlm.dll" )

Define the SNC parameters related to your environment. If SncLib is not defined, NetWeaver RFC Library uses library defined in environment variable SNC_LIB or SNC_LIB_64.

        public string SncQop { get ; set; }

        public string SncMyname { get; set; }

        public string SncPartnername { get; set; }

        public string SncLib { get; set; }

About

An easy way of making SAP RFC calls from .NET Core

License:Apache License 2.0


Languages

Language:C# 100.0%