Applications To SAP: Home Quick Answers Discussions Features Community Help Articles

Download as pdf or txt
Download as pdf or txt
You are on page 1of 15
At a glance
Powered by AI
The article discusses how to connect a .NET application to SAP using the SAP.NET Connector and make calls to ABAP functions. It covers downloading the connector, adding a proxy to the project, and establishing a connection at design time.

A .NET application can connect to SAP by downloading the SAP.NET Connector and adding a SAP Connector Proxy to the project. This will add the necessary references and create a WSDL file. A connection can then be established by adding the SAP server in the project.

To add a SAP Connector Proxy to a project, right click on the project file and select Add > New Item. Choose 'SAP Connector Proxy' from the options. This will automatically add references and create a WSDL file for the proxy.

Using the SAP.NET Connector to Connect your ... https://www.codeproject.com/Articles/24161/Us...

13,708,496 members Sign in

Search for articles, questions, tips

home articles quick answers discussions features community

help

Articles » Platforms, Frameworks & Libraries » .NET Framework » Utilities

Using the SAP.NET Connector to Connect your .NET


Applications to SAP
Andy_Schmidt, 6 Mar 2008

4.19 (22 votes) Rate this:

An article about using the SAP.NET connector to connect your .NET applications to SAP

Download source - 68.34 KB

Overview
This article will show how to establish a connection to SAP and how to call an ABAP function on SAP and pass data to
the function and receive data back from the function all via the SAP .NET Connector.

Introduction
If you are a .NET Software Developer, it's almost a given that you have been tasked at one time or another to interact
with various ERP systems. Sometimes, this task can be completed simply because you may be granted access directly
to the back end databases, however often, you need to communicate directly with the business logic layer of the ERP
system. This is often the case when working with SAP because of the powerful ABAP functions which reside within the
business logic layer of the system. Fortunately, SAP and Microsoft have teamed up to provide developers with the
SAP.NET Connector.

The SAP Connector for Microsoft .NET is a programming environment that enables communication between the
Microsoft .NET platform and SAP Systems. It supports SAP Remote Function Calls (RFC) and Web services, and
allows you to write various applications, for example, Web form, Windows form, and console applications within
Microsoft Visual Studio .NET. You can use all Common Language Runtime (CLR) programming languages such as
Visual Basic .NET and C#. This article will demonstrate how to get connected to SAP and how to call an ABAP function
and pass data to and from SAP. So, without further ado, let's get to the code!

1 de 15 26/9/18 2:56
Using the SAP.NET Connector to Connect your ... https://www.codeproject.com/Articles/24161/Us...

Establishing a Connection to SAP at Design Time


The first thing to note here is that your .NET applications can interact with SAP in two ways. First, as a client which calls
SAP, the server. The second way in which your .NET applications can interact with SAP is where your client acts as the
server and receives calls from SAP, the client. This article will focus on the former, and the latter will be discussed in a
forthcoming article. It should be noted that connecting your .NET applications to SAP as the client is much more
straightforward than when your .NET applications have to act as the server.
So, how do we connect a .NET application to SAP? Well, the first thing you need to do is download the SAP.NET
connector, which is free and can be obtained here. Once you have installed the connector, start Visual Studio .NET and
create a new Windows application. You might be tempted to go straight to the references of the project and add
references to the SAP .NET connector, however, this approach is not correct. The correct next step is to right click on
your project file and select Add, then New item. Once the dialog box opens, scroll to the bottom and you will find an
entry called “SAP Connector Proxy”, as show in figure 1 below:

Figure 1 – Adding the SAP Connector Proxy to your project.

After you add the proxy, you will notice that the system automatically adds the necessary references to your project as
well as creates a WSDL file called SAPProxy1.wsdl. This file will show up as a blank screen in Visual Studio, as shown
in figure 2 below:

2 de 15 26/9/18 2:56
Using the SAP.NET Connector to Connect your ... https://www.codeproject.com/Articles/24161/Us...

Figure 2: After the SAP Connector Proxy has been added.

Once the proxy has been added, it's time to add the SAP Server to your project. Click View, then click Server Explorer
and you will see that an option for SAP is included in the list. Click the SAP entry and it will expand and show
"Application Servers". Right click this and select "Add Application Server". A dialog box similar to Figure 3 below will
appear:

Figure 3 – SAP Application Server Dialog Box.

This is where you will need to set your parameters for establishing a connection to your SAP server. Change the

3 de 15 26/9/18 2:56
Using the SAP.NET Connector to Connect your ... https://www.codeproject.com/Articles/24161/Us...

Destination Type property to “Custom”, then add the necessary values for the following properties:

User Name
Password
AppServerHost
SAPRouterString
HTTP Port
Client
System Number

These variables will depend on your SAP installation. Check with your SAP Administrator for the specific settings in
your environment.

Once you have the properties set, you can then establish your connection to SAP. Expand the new server, then expand
the Functions entry. This will provide a list of all ABAP functions that are contained in your SAP environment. See figure
4 below:

The next step is to locate the function that you wish to call. When you find it, simply drag and drop it onto the
SAPProxy1.sapwsdl file. It will automatically create several objects and even code files that relate to your particular
function (note that you need to be viewing all files in your project to see the code files that the process creates):

4 de 15 26/9/18 2:56
Using the SAP.NET Connector to Connect your ... https://www.codeproject.com/Articles/24161/Us...

Figure 5: After the SAP objects are created,


note the additional code files automatically created.

Once this step is created, the rest is quite easy. To demonstrate, my sample uses a very simple ABAP function that
takes a contract number and a line item number and returns an invoice. I have created a form with 1 button and a
textbox. The code behind my button will do the following:

Establish a connection to SAP


Create an object to allow me to invoke the ABAP function and return the values that it provides.

Here is the code listing (note that I have removed the actual connection values – you need to substitute the values with
your connection parameters):

Hide Shrink Copy Code

Private Sub Button1_Click(ByVal sender As System.Object, _


ByVal e As System.EventArgs) Handles Button1.Click

Dim BAPI As New SAPProxy1


Dim conStr As String = "ASHOST=AppserverIP SYSNR=sysnumber CLIENT=clientnumber _
USER=user PASSWD=password"

BAPI = New SAPProxy1(conStr)

Dim SAPtbl As New ZSDUS_INVOICETable


Dim Ret As New VS2003_SAP_Connect.BAPIRETURNTable

Try
'params are contract # and line item
BAPI.Zsdus_Get_Invoice_Number("0045001126", "000010", SAPtbl, Ret)
Catch ex As Exception
MsgBox(ex.Message)
End Try

5 de 15 26/9/18 2:56
Using the SAP.NET Connector to Connect your ... https://www.codeproject.com/Articles/24161/Us...

'ret table of success or failure


'ret table is always empty upon success if ret contains a
'value that indicates failure
If Ret.Count > 0
Then
MsgBox(Ret.Item(0).Message.ToString)
End If

TextBox1.Text = (SAPtbl.Item(0).Vbeln.ToString)
End Sub

So what’s going on here?


We do the following:

Declare a variable to hold the connection string.


Create an instance of our Proxy.
Establish the connection.
Create the parameters that the ABAP function calls for. In this case its two tables – note these are strongly
typed.
Call the function passing in the parameters.
Examine the Return table to see if we had success or any errors.
Read out the first item from the table, a field called Vbeln and assign its value to a text box.

See the results below:

Figure 6 – The results.

As you can see, the function call returned a data table with invoice information. I have chosen to only display one field
for simplicity sake, but the actual data returned is all the contents of the invoice. We could have loaded this information
to a data grid, for example.

Conclusion
This article shows a real world example of connection to SAP and calling an ABAP function from .NET via the SAP.NET
connector. As you can see, by using the connector as a client to SAP, we can easily connect to the SAP server and
invoke any function that we have permissions to execute. This ability add tremendous flexibility to your .NET
applications when you need to integrate with SAP.

6 de 15 26/9/18 2:56
Using the SAP.NET Connector to Connect your ... https://www.codeproject.com/Articles/24161/Us...

About the Author


Andrew Schmidt is a consultant with Custom Software By Preston. He has over 10 years of software development
experience in a range of industries including manufacturing, government, health care, and telecommunications. He has
developed enterprise systems that integrate with SAP and other ERP systems. He resides in Chicago with his wife and
1 year old son and can be reached via email at [email protected] or at Custom Software by
Preston.

License
This article, along with any associated source code and
files, is licensed under The Code Project Open License
(CPOL)

Share
TWITTER

About the Author


Andy_Schmidt
Unknown

No Biography provided

Comments and Discussions

You must Sign In to use this message board.

Search Comments

Spacing Relaxed Layout Open All Per page 25 Update

7 de 15 26/9/18 2:56
Using the SAP.NET Connector to Connect your ... https://www.codeproject.com/Articles/24161/Us...

First Prev Next

Is this 3.0 or 4.0- Dot Net Connector? And 8-Sep-16 6:38


No source code, only .DLL's

This thread looks a bit DEAD.. no posts since 2013...??


Are the DLLs Current? Do they Still Work?
Are the DLLs in the ZIP file a 3.0 or 4.0 Connector?
Can you provide the actual Source Code?

Thanks!

Sign In · View Thread

My vote of 4 DuraiAmuthan 25-Sep-13 4:37

Explanation is good

Sign In · View Thread

coonector 3.0 cookie_monsta 6-Mar-13 21:39

Where can I get the connector from without having to log into sap?

Sign In · View Thread

Has anyone tried the above example? Andreas Kasapleris 6-Mar-13 12:16

I want to ask if anyone has tried the above. Although I have installed SAP Connector with VS2010
nothing of the above example seems to work. SAP Proxy does not even appear as on option!

Sign In · View Thread

Re: Has anyone tried the above Jim F. Johnson 14-Jan-15 18:34
example?

Not sure about the current options for RFC integration from VS2010. Has anyone tried with other
tools? Is SAP Connector 3.0 working with the VS 2010 IDE?

---
D.

Sign In · View Thread

Connecting to SAP from .net using single kasun.uggalla 21-Nov-11 23:26


sign on

8 de 15 26/9/18 2:56
Using the SAP.NET Connector to Connect your ... https://www.codeproject.com/Articles/24161/Us...

Hi Andy,

Hope your doing good. I was doing some research on google and came across one of your articles.

We are working on a Windows application which is a c sharp.net application which connects to SAP and does
some transactions. Currently we use the .net connector to connect to SAP. Here user needs to enter the user
name and password in order to log in to the system. Now we have a requirement where user doesn't want to
enter the credentials. They want us to connect to SAP using windows authentication. Single Sign on is already
configured in SAP. I just want to know how can i connect to SAP using the windows login details.
Please help me out as i need to do a prototype and confirm that this is possible.

Thanks and Best Regards,


Shezan
email : [email protected]

Sign In · View Thread

My vote of 5 kasun.uggalla 21-Nov-11 23:23

Hi Andy ,

This is a great article , I have a requirement to login to SAP using Single Sign on , Will you be able to help me
out. IF you can please send me a mail on [email protected] , thanks

Sign In · View Thread

Source Code missing !!!!! mr.wadg 29-Nov-10 3:54

I tried to download the source code of this article....but when I download the file attached occurs that this .rar
file contains a set of images, and scripts but doesn't have the source code....

please help!!!!!!!!!!111

Sign In · View Thread

Error I::001 Only available with the RFC Alexey120 18-Jan-10 1:07
library from 4.0C onwa

I develop .net application which download a document via SAP-RFC_CALL. Inside this RFC I use standard
BAPI’s for check out, eg BAPI_DOCUMENT_CHECKOUTVIEW2 but I get an error in out RETURN parameter -
I::001 Only available with the RFC library from 4.0C onwa
Please, help if you know how to solve this issue.

Best regards,
Alex

Sign In · View Thread 5.00/5 (1 vote)

Download SAP Connector 2.0 bojanv55 3-Dec-09 6:33

9 de 15 26/9/18 2:56
Using the SAP.NET Connector to Connect your ... https://www.codeproject.com/Articles/24161/Us...

Here it is, but you'll need dotnetFramework 1.1 and Visual Studio 2003...

http://www.megaupload.com/?d=GUZ76550[^]
http://rapidshare.de/files/48781419/SAP.Net.Setup_2.0.rar.html[^]

Sign In · View Thread

Re: Download SAP Connector 2.0 peterklausen 21-Feb-10 14:23

There's a new tool (http://www.aconcaguait.com/explorerproxygen2008.php[^]) to evaluate. I've


requested a trial (Only tried the VS2008 version). It worked just fine and has lower prices than other
similar tools. The feature set seems adecuate as well (RFC documentation, code snippets, RFC Servers).

It also seems to be using the latest version of librfc32.dll (allowing more than 8-chars passwords, etc)

there's also a how-to guide....http://www.youtube.com/watch?v=72nM-vuYfFI[^]

worth to take a look.

Cheers!

PK.

Sign In · View Thread

Was there ever an article that showed eddiem9 2-Sep-09 6:04


how to make a server to listen for
messages from SAP? (NM)

Thanks,

Sign In · View Thread

Re: Was there ever an article that goeli 2-Feb-12 1:37


showed how to make a server to listen
for messages from SAP? (NM)

No. At least I couldn't find one yet.

Sign In · View Thread

Unable to Establish connection to R/3 kyreddy 25-Aug-09 18:08


System xxxx.xx.x.xxx
System(Client=0,System=1) [modified]

I am getting the above error when i am dragging and droping an ABAP function from the server explorer
window onto the sapproxy designer.The full details of the error window are as given below.

10 de 15 26/9/18 2:56
Using the SAP.NET Connector to Connect your ... https://www.codeproject.com/Articles/24161/Us...

Info:Using Logging implemenation "AII Logging"


Exception in thread "main" com.sap.aii.upload.sap.SAPConnectionException$ConnectFailed:Unable to
Establish connection to R/3 System xxxx.xx.x.xxx System(Client=0,System=1)
at com.sap.aii.upload.sap.SAPConnection.Connect(SAPConnection.Java: 103)
at com.sap.aii.upload.sap.SAPConnection.<init>(SAPConnection.Java: 38)
at com.sap.aii.upload.tool.rfc2wsdltool.getwsdlforrfsc(rfs2wsdltool.Java:81)
at com.sap.aii.upload.tool.rfc2wsdltool.main(rfc2wsdltool.java:196)

modified on Wednesday, August 26, 2009 4:46 AM

Sign In · View Thread

Re: Unable to Establish connection to Navin Pai 2-Feb-12 1:12


R/3 System xxxx.xx.x.xxx
System(Client=0,System=1) [modified]

Hi,

Did you get a solution to your problem. I too am facing a similar problem. I am connecting to the SAP server
of our client from my machine via VPN. We are using VS.Net 2003 with SAP .Net Connector 2.01. We are
able to connect to the SAP server and view the functions. Only when I drag and drop the function onto the
designer get the following message

Hide Copy Code

INFO: using logging implementation "AII Logging" Exception in thread "main"


com.sap.aii.upload.sap.SAPConnectionException$ConnectFailed: Unable to
establish

connection to R/3 system 10.200.2.71(system=0,client=512) at


com.sap.aii.upload.sap.SAPConnection.connect(SAPConnection.java:103) at
com.sap.aii.upload.sap.SAPConnection.<init>(SAPConnection.java:38)
at
com.sap.aii.upload.tool.RFC2WSDLTool.getWSDLforRFCs(RFC2WSDLTool.java:81)
at
com.sap.aii.upload.tool.RFC2WSDLTool.main(RFC2WDLTool.java:196)

I was wondering if you found a solution to your problem. I am aware you faced this long time back but if you
could recall and help me, I would be very happy.

Regards

Navin

Sign In · View Thread

Re: Unable to Establish connection to Navin Pai 2-Feb-12 1:15


R/3 System xxxx.xx.x.xxx

11 de 15 26/9/18 2:56
Using the SAP.NET Connector to Connect your ... https://www.codeproject.com/Articles/24161/Us...

System(Client=0,System=1) [modified]

Hide Copy Code

Hi,

Did you get a solution to your problem. I too am facing a similar


problem. I am connecting to the SAP server of our client from my machine
via VPN. We are using VS.Net 2003 with SAP .Net Connector 2.01. We are
able to connect to the SAP server and view the functions. Only when I
drag and drop the function onto the designer get the following message

<pre lang="xml">INFO: using logging implementation &quot;AII


Logging&quot; Exception in thread &quot;main&quot;
com.sap.aii.upload.sap.SAPConnectionException$ConnectFailed: Unable to
establish

connection to R/3 system 10.200.2.71(system=0,client=512) at


com.sap.aii.upload.sap.SAPConnection.connect(SAPConnection.java:103) at
com.sap.aii.upload.sap.SAPConnection.&lt;init&gt;(SAPConnection.java:38)
at
com.sap.aii.upload.tool.RFC2WSDLTool.getWSDLforRFCs(RFC2WSDLTool.java:81)
at
com.sap.aii.upload.tool.RFC2WSDLTool.main(RFC2WDLTool.java:196)</pre>

I was wondering if you found a solution to your problem. I am aware you


faced this long time back but if you could recall and help me, I would be
very happy.

Regards

Navin

Sign In · View Thread

Can't connect to Server SAP to get the FlorianBCN 30-Oct-08 23:52


functions

I can't get to connect to SAP.


In visual studio, in the servers windons, I add the sap server passing all the details. it build up a good conection
string:

CLIENT=200 USER=****** PASSWD=****** LANG=ES ASHOST=10.160.60.2 SYSNR=16

2 nodes appears, BOR and Funntions.


In the functions node, I get nothing.
When I try open the BOR node, it starts to think and then I get:

SAP_CMINIT3 : rc=20 > Connect to SAP gateway failed


Connect_PM GWHOST=10.160.60.2, GWSERV=sapgw16, SYSNR=16

LOCATION CPIC (TCP/IP) on local host


ERROR partner '10.160.60.2:3316' not reached

12 de 15 26/9/18 2:56
Using the SAP.NET Connector to Connect your ... https://www.codeproject.com/Articles/24161/Us...

TIME Fri Oct 31 10:12:19 2008


RELEASE 710
COMPONENT NI (network interface)
VERSION 39
RC -10
MODULE nixxi.cpp
LINE 3133
DETAIL NiPConnect2: 10.160.60.2:3316
SYSTEM CALL connect
ERRNO 10060
ERRNO TEXT WSAETIMEDOUT: Connection timed out
COUNTER 1

So I looked at what port the SAP logon connects to and notice it was a different one : 3216 instead of 3316.

I tried to pass the port in the AppServerHost property: 10.160.60.2:3216

It doesn't even take time to think and gives me:

SAP_CMINIT3 : rc=20 > Connect to SAP gateway failed


Connect_PM GWHOST=10.160.60.2:3216, GWSERV=sapgw16, SYSNR=16

LOCATION CPIC (TCP/IP) on local host


ERROR hostname '10.160.60.2:3216' unknown

TIME Fri Oct 31 10:25:19 2008


RELEASE 710
COMPONENT NI (network interface)
VERSION 39
RC -2
MODULE nixxhsl.cpp
LINE 233
DETAIL NiHsLGetNodeAddr: hostname cached as unknown
COUNTER 2

Don't know what to do next..... Help!

Sign In · View Thread

Re: Can't connect to Server SAP to get 1-Nov-08 13:59


the functions

I have almost the same problem, it seems the connection is refused:

SAP_CMINIT3 : rc=20 > Connect to SAP gateway failed


Connect_PM GWHOST=10.200.52.25, GWSERV=sapgw00, ASHOST=10.200.52.25, SYSNR=00

LOCATION CPIC (TCP/IP) on local host


ERROR partner not reached (host 10.200.52.25, service 3300)

TIME Sat Nov 01 17:40:06 2008


RELEASE 640
COMPONENT NI (network interface)

13 de 15 26/9/18 2:56
Using the SAP.NET Connector to Connect your ... https://www.codeproject.com/Articles/24161/Us...

VERSION 37
RC -10
MODULE nixxi_r.cpp
LINE 8724
DETAIL NiPConnect2
SYSTEM CALL SiPeekPendConn
ERRNO 10061
ERRNO TEXT WSAECONNREFUSED: Connection ref

Someone knows if is it necesary an special configuration on Basis??

Sign In · View Thread

Re: Can't connect to Server SAP to Check here to remove 1-Dec-08 22:09
your current profile picture
get the functions

Apply sap note 148832.

Sign In · View Thread 5.00/5 (1 vote)

Re: Can't connect to Server SAP juarez.ebpetroleo 3-Mar-09 9:35


to get the functions

Check the following files:


\windows\saplogon.ini
\windows\sapmsg.ini
\windows\system32\drivers\etc\services

In the later check if you have the correct port number for the sap service.
You can check which port would be by running the dos command 'netstat -a' while running SAPGui.

Sign In · View Thread

Re: Can't connect to Server SAP to get 9-Apr-15 19:03


the functions

hey you are not connect to sap server

Sign In · View Thread

No SAP server in server explorer boethius 3-Oct-08 1:14

Hi,
I have installed Sap Net Connector, and I added the Proxy as new Item, but when it came to see the Server
Explorer the SAP option did not appear at all.
What do you think?

14 de 15 26/9/18 2:56
Using the SAP.NET Connector to Connect your ... https://www.codeproject.com/Articles/24161/Us...

Sign In · View Thread

Re: No SAP server in server explorer Srinivas-Miriyala 15-Oct-08 4:04

Try refreshing Data Connections in the Server explorer.

Sign In · View Thread

Re: No SAP server in server explorer Sunil_Pawar 27-Nov-08 23:29

Refresh the Server Explorer,


I was also facing the same problem but work around by refreshing it, its easy

Sign In · View Thread

SAP.NET Connector for 64 Bit Member 3713623 5-Aug-08 14:34

I am facing problem when I try to use the SAP.NET connector on 64bit processor:

Error:An attempt was made to load a program with an incorrect format. (Exception from HRESULT:
0x8007000B)

I guess the dependent components like "sap.connector.dll","sap.connector.rfc.dll" and/or "librfc32.dll" are 32bit
compliant. What is the workaround for this?

I just copied librfc32.dll into system32 folder of

Sign In · View Thread

Last Visit: 31-Dec-99 18:00 Last Update: 25-Sep-18 14:52 Refresh 1 2 Next »

General News Suggestion Question Bug Answer Joke Praise Rant


Admin

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile


Web01-2016 | 2.8.180920.1 | Last Updated 6 Mar 2008 Seleccionar idioma ▼
Layout: fixed | Article Copyright 2008 by Andy_Schmidt
fluid Everything else Copyright © CodeProject, 1999-2018

15 de 15 26/9/18 2:56

You might also like