Jul 20

Building an SAP .Net Connector Proxy

Overview

The SAP .Net Connector is an SAP-supplied control that works only with Visual Studio 2003. This blog post describes how to create a VS 2003 project that will allow you to use the SAP .Net Connector in later versions of Visual Studio.

[Editor’s Note]
This blog is the second of a multi-part series describing how to use the SAP .NET Connector:

 

 

 

  1. Introduction to the SAP .Net Connector
  2. Building an SAP .NET Connector Proxy
  3. Using the SAP .Net Connector in Visual Studio 2008

 

Introduction

We will use Visual Studio 2003 and create a Dynamic Link Library (DLL) that encapsulates the desired SAP .Net Connector functionality. We can use the DLL that we create in a Visual Studio 2008 project.

To illustrate the process, we will build up, over the course of several blog posts, a system that is capable of receiving an IDOC from an SAP host. This system will be known as the Three Letter Acronym system, or TLA.

Build an SAP Proxy

Our first task is to use the SAP .Net Connector to build a proxy that we can incorporate into Visual Studio 2008 projects.

The approach is to first add the SAP .Net Connector to a Visual Studio 2003 project. Then, we will attach to an SAP host to browse available functions. We will select the desired functions to be included in our SAP proxy.

Then, we will build the VS 2003 project into a DLL that can be used in Visual Studio 2008.

Start a Visual Studio 2003 Project

After you have installed the SAP .Net Connector, start a new Visual Studio for .Net 2003 project. Name the project “TlaSapProxy.” Choose the “Class Library” C# template.

Creating a new SAP Proxy project

Creating a new SAP Proxy project

We don’t need the default Class1.cs file that is created, so close the Class1.cs module that is displayed, and remove Class1.cs from the TlaSapProxy project.

Add a Reference to the SAP .Net Connector

Now we need to add a reference to the SAP .Net Connector. From the Solution Explorer view, expand TlaSapProxy / References. Right click on References and choose Add Reference. From the .Net tab, double-click both SAP.Connector.dll and SAP.Connector.Rfc. Click OK to add the reference to your project.

Adding References to SAP .Net Connector

Adding References to SAP .Net Connector

 

Establish a Connection to an SAP Host

We will use the Visual Studio design time environment to attach to an SAP Host. From the Visual Studio View menu, select Server Explorer. Expand the SAP node. Right click on Application Servers and select Add Application Server.

For Destination Type, select Custom Logon Settings from the drop down list. Enter a valid SAP Username, Client, and Password. For the AppServerHost, enter the SAP host name, or the IP address of the desired SAP host. Be sure to fill in the Language field.

SAP Server Connection Properties

SAP Server Connection Properties

If things go well, at this point you will have an SAP Application Server established. You should see two new nodes on the Server Explorer display: BOR and Functions. Under BOR, you can expand either the Alphabetical or Hierarchical nodes to see available object definitions.

Browse SAP Functions

To display an SAP function using the Server Explorer, you have to create a function ‘filter,’ which selects which functions from the SAP Host you want to display. To do this, right click on Functions and choose Add Function Filter. In our proxy, we are going to be using some RFC functions, so, in the NameFilter field, enter RFC* (the asterisk is a wild card). Click OK, then expand Functions, then expand Filter1. After a moment, the screen will display a list of SAP functions that match our filter.

Creating a New Function Filter

Creating a New Function Filter

SAP Function Filter Display

SAP Function Filter Display

 

Select Desired SAP Functions

As you can see, there are many functions to choose from. When we build our SAP proxy, we will select just the functions we need.

For our TLA SAP Proxy we are building, we only need RFC_GET_SYSTEM_INFO. As with most SAP functions, RFC_GET_SYSTEM_INFO returns an object of a custom type that includes all of the results of the function call.

From the Visual Studio 2003 Solution Explorer, right click on the TlaSapProxy project and choose Add, then Add New Item. Scroll through the list of Templates and click on SAP Connector Proxy, then click OK to add the new item to the project.

Adding an SAP Connector Proxy Object

Adding an SAP Connector Proxy Object

What you have at that point is a Visual Studio design surface to which we can add SAP function definitions. The design surface is displayed as SAPProxy1.sapwsdl. We are basically creating a WSDL file that will be used to generate our desired DLL.

Adding SAP Functions to a Proxy

Adding SAP Functions to a Proxy

To include an SAP function, in our case RFC_GET_SYSTEM_INFO, display the Server Explorer. Expand the SAP Application Servers to the desired server, then click on RFC_GET_SYSTEM_INFO. Drag RFC_GET_SYSTEM_INFO to the SAPProxy1.sapwsdl and drop it there.

The screen will display ‘Retrieve Data.’ When it is done, you will see two things added to the WSDL. First is the function call definition (method). Second is a class definition for what is returned from the function. You can right click on these and select Properties to view details of what is contained therein.

Building the Project

Now that we have selected all of the desired SAP functions that we want to include in our proxy, we are ready to build the project.

Because we selected a Class Library as our starting project template, our project is already set to build a class module (DLL). To build the DLL, right click on the TlaSapProxy project and select Build.

This will compile our WSDL file into a DLL file that we will be able to use in Visual Studio 2008.

Summary

The SAP .Net Connector is built for Visual Studio 2003. By using Visual Studio 2003 to create a DLL, we can use the SAP .Net Connector in Visual Studio 2008 (or later).

We do this by establishing a connection to an SAP host, selecting the desired functions, and creating an SAP proxy object that contains the desired functions. When we build this project, the resulting DLL can be used in Visual Studio 2008.

Our next blog post will describe how to use our newly created SAP proxy in a Visual Studio 2008 project.

Avatar

About The Author

7 Comments

  1. […] previous post described how to use Visual Studio 2003 and the SAP .Net Connector to create a Dynamic Link Library […]

  2. […] Building an SAP .NET Connector Proxy […]

  3. Avatar
    arshad ali
    April 5, 2010 at 4:14 am · Reply

    Sir, i am fellowing the step but it faild to connect, afther give the detail, this RCA system, and server name is pwdf3142_CU5_75 and giving all the detail, user name, password, clinet, and systemnumber i give 0 and when i expend the tree the following error is come.

    Connect to SAP gateway failed
    Connect_PM GWHOST=pwdf3142_CU5_75, GWSERV=sapgw00, ASHOST=pwdf3142_CU5_75, SYSNR=00

    LOCATION CPIC (TCP/IP) on local host
    ERROR hostname ‘pwdf3142_CU5_75’ unknown

    TIME Mon Apr 05 12:12:39 2010
    RELEASE 640
    COMPONENT NI (network interface)
    VERSION 37
    RC -2
    MODULE ninti.c
    LINE 336
    DETAIL NiPGetHostByName2: hostname ‘pwdf3142_CU5_75’ not found
    SYSTEM CALL gethostbyname_r
    COUNTER 1

    can any body help me

  4. Avatar
    uschmidt
    June 17, 2010 at 9:27 am · Reply

    Arshad,
    “pwdf3142_CU5_75” is not the real hostname. A SAP system uses a concatenation of “hostname + system ID + system no.” when it displays it’s details.

    Try pwdf3142 as hostname and 75 as system number.
    If that still doesn’t work, ask your SAP system admin for the correct values. Perhaps there is a firewall in front of the SAP system, in which case you would need an additional router string.

  5. Avatar
    btumer
    August 5, 2010 at 3:12 pm · Reply

    Excellent walkthrough. Wish I had found this a year ago. But there’s one thing I’m still not clear on. Is changing the connection string sufficient to change the app server? I want to be able to test these RFCs without requiring that they be moved to PRD to do so.

    #if DEBUG
    connectionString = “connection string to QAS”;
    #else
    connectionString = “connection string to PRD”;
    #endif

  6. Avatar
    nsadaf
    January 11, 2011 at 4:18 am · Reply

    hi,

    Im usind SAP.Net Connector 3.0 …Can i Build an SAP Proxy in Visual Studio 2008?
    and how to use NCO 3.0 in VS 2008?

  7. Avatar
    Mayank
    March 3, 2016 at 11:42 pm · Reply

    hi I am using VS 2003 framework v1.1 but i am not able to referece the 2 SAP dLLS into my project.
    These are not appearing in the .net Dlls section ann when i try to add them by browsing then also the add button is getting greyed out. any comments on this please

Leave a reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

This site uses Akismet to reduce spam. Learn how your comment data is processed.