SIGN UP MEMBER LOGIN:    
ARTICLE

Solution Development using SAP .NET Connector in Visual Studio .NET

Posted by Balaji Sundaram Articles | Visual Studio .NET December 23, 2010
This document mainly goes through some important points which would help the programmer to successfully implement an application using SAP & ASP.NET.
Reader Level:


INTRODUCTION:

The document basically goes through a brief description of the solution of an application we had worked on. The part explained in this article has been successfully executed and tested.

This document mainly goes through some important points which would help the programmer to successfully implement an application using SAP & ASP.NET. C# has been used as a programming language for an application to interface connection with SAP and consume its function.

SAP CONNECTION WITH .NET:

The SAP .NET Connector tool enables .NET portal components to connect to SAP systems. It allows portal component developers to call the functions of SAP systems. These functions are called RFCs (Remote Function Call), or BAPIs (Business Application Program Interface). These functions are written in ABAP and are an integral part of SAP systems, but a customer can add his own functions, using ABAP development tool.


The SAP .Net Connector 2.0 is especially designed for .NET developers working inside VS2003. It allows the developer the means to easily create SAP Proxies to the required functions (C# or VB.NET), and later integrate these proxies to his project. These proxies connect to the SAP system and call the RFC functions using SAP RFC protocol or SOAP. This software can be downloaded from SAP site.

After downloading, install the software.

Initially it has to start with the installation of the SAP .Net Connector 2.0 on the system.

After installation, open the Visual Studio 2003 and add a new SAP application server. Follow the steps listed below for adding the new SAP application server:

  1. Open Server Explorer.
  2. Expand SAP and right click on application servers.
  3. Click on "Add Application Server" and following dialog box will be opened.
  4. Change the destination type to Custom Login Settings and then enter the username, client, password, AppServerHost.

    image1.gif

On clicking of OK button, the SAP application server will be added in the server explorer as follows.
image2.gif

Expand the tab to see the SAP functions:

image3.gif

image4.gif

Then, we can use the RFCs (Remote Function Call), or BAPIs (Business Application Program Interface) in Visual Studio 2003.

For consuming RFCs and BAPIs in Visual Studio 2003, follow the steps below:

Step 1
  1. Open Visual Studio 2003
  2. Create New Project and Select Class Library and give appropriate name to it.

    image5.gif

Step 2

Then the reference to the SAP Connector needs to be added.
  1. Right Click on Project and select Add References.
  2. Click on .Net tab and add the two references, SAP.Connector.dll and SAP.Connector.Rfc as follows:

    image6.gif

Step 3

After the creation of class library project, we will need to create a SAP Connector Proxy item as shown below.

Right Click the Project and Click on Add New Item
  1. Select SAP Connector Proxy
  2. Give appropriate name for the file. (Extension of the file will be sapwsdl)

    image7.gif

Step 4

Open the sapwsdl file in Design view. Add the functions from the server explorers by dragging and dropping the functions from server explorer as follows:

image8.gif

image9.gif

After dragging and dropping the functions from the server explorer, the SAPProxy.sapwsdl file will look like following:

SPECIFIC CODING DETAILS USED IN MY SOLUTION TO GIVE AN IDEA OF THE ABOVE EXPLAINED PROCEDURE:
  1. Declare an object for the SAPProxy.sapwsdl as follows and create a property for it also:

    private SAPProxy proxy
    public SAPProxy Proxy
    {
    get { return proxy; }
    set { proxy = value; }
    }
     
  2. Get the connection string from the web.config as follows:

    connectionString = ConfigurationSettings.AppSettings["ConnectionString"];
     
  3. Create an instance of SAPProxy.sapwsdl as follows:
    proxy = new SAPProxy(connectionString);
     
  4. Consume the function as follows:

    Proxy.function(parameter names);
     
  5. You can catch RFC specific exceptions using the RfcException class.
     
  6. The proxy instance can be destroyed as the following:

    proxy.Connection.Close();
    proxy.Connection.Dispose();
    proxy.Connection = null;

All the functions pointed out are case-sensitive and are to be used in proper order.

The above mentioned code lines are used in our solution which are successfully tested.

Conclusion:

The document provides brief information regarding the connection procedure of .NET framework with SAP and how to consume SAP functions. Small code lines give an idea to the reader how to get started with the process. More importantly the description will help the reader not just to code but to understand the classes, components and the methods provided.

Login to add your contents and source code to this article
Article Extensions
Contents added by just tsha on Jul 27, 2011
Hi! please assist. I have just installed the .Net SAP Connector 3.0 , but I dont get to see the .Net SAP Connector Proxy when I go to Add New Item on Visual Studio 2008.

It is not there on the Templates.

Please help!!!
share this article :
post comment
 

Hi! please assist. I have just installed the .Net SAP Connector 3.0 , but I dont get to see the .Net SAP Connector Proxy when I go to Add New Item on Visual Studio 2008. It is not there on the Templates. Please help!!!

Posted by just tsha Jul 27, 2011

Hi, SAP .NET Connector 3.0 support current Windows releases (Windows XP 32 Bit, Windows 2003 32/64 Bit (x64), Windows Vista 32/64 Bit (x64), Windows 2008 64 Bit (x64) and later Windows 7) as well as up-to-date Microsoft .NET Runtime versions (2.0, 3.0 and 3.5). Can SAP connector 2.0 connect to .net framwork 3.5 and .net 4.0 . What about VS2010 and SQL 2008 or we need to use SAP connector 3.0 only?

Posted by sonali lad Jul 02, 2011

The connector works for all and RFC call is performed by TableReader. Create Entry in Table SNCSYSACL via SNC0 This table contains a list of trusted domain accounts or SNC. Start SAP and run SNC0 Make sure to enable the RFC/CPIC/Ext ID options for more https://websmp103.sap-ag.de/connectors

Posted by Balaji Sundaram Dec 23, 2010

SAP .NET Connector is developed by SAP. You should have some experiences with ABAP/4 and function modules and the SAP.NET Connector installed. Any project that uses the Connector must have a reference to SAP.Connector.dll. The Connector is available at http://service.sap.com/connectors and an overview is given at http://www.microsoft-sap.com/net_connector.aspx.

Posted by Balaji Sundaram Dec 23, 2010

Hi, not sure if these question got posted properly so here they are again: 1st: Does this solution works only on vs2003? what about for vs2005 and/or vs2008? 2nd: What roles do I need to have access in SAP side in order to be able to use RFCs/BAPIs? any special tcode?

Posted by Francisco Castellanos Dec 23, 2010
Become a Sponsor
PREMIUM SPONSORS
  • The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Become a Sponsor