Introduction
This short material will guide on the following integration points
- Connecting to SAP system via SAP .NET Connector (also called as sapnco libraries)
- Access a RFC function from SAP System and get the data.
- Exception handling.
For this Tech Tip will create a console application using C#
SAP .Net Connector
SAP .NET Connector 3.0 is the current version of SAP's development environment for communication between the Microsoft .NET platform and SAP systems. This connector supports RFCs and Web services. It allows developers to write different applications such as Web form, Windows form, or console applications in the Microsoft Visual Studio.Net. With the SAP .NET Connector, developer can use all common programming languages, such as Visual Basic. NET, C#, or Managed C++.
Step 1: Download the sapnco libraries from SAP official site and reference to the Visual Studio project as shown below,
- sapnco.dll
- sapnco_utils.dll
sapnco libraries details as follows,
Step 2: Append the following to app.Config.
Note: Provide the required IP and Credentials to connect to target SAP System as received from SAP team.
Step 3:
In this example, will show how the program is accessed in getting the invoice details from SAP system
The below methods will help to connect to the SAP System, access the RFC function by passing the necessary input and output parameters.
Note: In RFC Terms the input parameters are called import and output as export parameters.
Do request the SAP team to provide the RFC function name, its import and export parameters which will be helpful to build the logic.
Step 4:
- Build the solution and the following errors will hit.
Solution:
as the sapnco libraries support .Net 4.0, set the console application to Target Framework to 4.0.
- Again build the solution, it will be successful one. On execution another error will shoot up as below,
Solution: sapnco libraries are available for (x86) and (x64) platforms. Here I have used 32 bit library of sapnco where as my laptop is x64.
Set the following in project properties where Platform target to be x86. Now Execution will be successful.
Step 5:
Program Output:
Step 6:
Exception handling:
- Apply the below try catch blocks as below to handle exceptions.
Add On:
- Consider WCF service instead of console application for the above example.
- The Web Service will be deployed in IIS.
- The followings points to be kept in mind during configuration.
Since we used x86(32 bit) sapnco libraries, and servers in general x64 (64 bit) the following need to be applied to application pool of the Web Application,
- Enable 32-Bit Application – Set to True (by default the value is false),
- Sapnco libraries require “Microsoft Visual C++ 2010 x86 Redistributable Setup”, do install this setup if Web Service throws issues.
Read more articles on .NET: