Friday, April 18, 2008

Connecting .Net Application to SAP server using SAP.Net Connector 2.0

Connecting .Net Application to SAP server using SAP.Net Connector 2.0


Introduction
Application Integration is the key to extracting maximum value from application and development investments. Almost all systems have some Application Integration requirement. Application integration bridges the gap between unique enterprise requirements and commercial offerings by enabling different applications to be combined within the same automated systems.

Communication between applications of different systems in the SAP environment includes connections between SAP systems as well as between SAP systems and non-SAP systems. Remote Function Call (RFC) is the standard SAP interface for communication between SAP systems and non-SAP systems. The RFC call can be used to perform a wide variety of operations and achieve a better and simple means of integration with the external system.

Using the SAP.NET Connector .NET Windows and Web form applications can be written that have access to SAP business objects (BAPIs) and can develop client applications for the SAP Server using either RFCs or HTTP/SOAP/XML.


Connectivity improvements in SAP Connector for Microsoft .Net 2.0
The Proxy Wizard has been removed. It is replaced by the extended designer and the new Server Explorer extension. When you add a new “Connection” class, an empty SAPWSDL file opens in the designer. To populate it with functions or a business object, drag the required item from the Server Explorer and drop it onto the designer.

Steps to connect to SAP Server from .Net Application

Execute the SAP.Net setup 2.0 installer file. It will create SAP Connector Proxy and SAP Login Form classes accessible in VS.Net to connect to SAP server.





Follow below steps:
Open the Server Explorer window. The “SAP” root node is visible. If not, choose the "Data Connections" node and click on the "Refresh" button.
Expand and select the "Application Servers" node. Right-click and choose “Add Application Server…”.
In the dialog box enter the logon information you want and click “Ok”. (Fig 2)
Open the new server node.
If you want to add a business object, open the “BOR” node and browse to required object. Drag the object, for example “Job” or “Employee”, to the designer.
If you want to add a single method, open the object and drag the method.




Functions can be added as follows:First, add a function filter by right-clicking the “Functions” node and selecting “Add new filter”. When you have entered the required information, expand the filter and drag the single function or the filter node (for all functions inside the filter) to the designer.





SAP connector for Microsoft .NET 2.0 does not have the “Connect code” feature. We think that this is acceptable because of the new “Connection wire up” feature that allows you to select the required connection without writing any code.
Using ASP.NET WebForm apps (alternatively, you can use the procedure for “Windows Forms”) proxy class can be added and populated with all required functions.

Add a “SAP Login Page” to the project.
Open the “SAP Login Page” in the Web form designer.
Modify the settings in “destination1” of the SAPLogin1.aspx. An easier method is to drag the “SAP Server” node of the system you want to connect to from the Server Explorer while holding the “Shift” key. This will update “destination1” with the settings from the dragged SAP server.
Open your Web form designer, for example, WebForm1.aspx.
Go to the SAP Proxy toolbox. You see an item with the name of your proxy class, for example, "SAPProxy1". Drag it to your “Web Forms” designer.
You see the proxy object in your designer, for example, “sapProxy11”. In the “Property” window, go to the “Connection” property and click on the drop-down icon.
Select “…from Login Page”. The designer automatically adds all necessary code to show the login page and connect to the SAP server. You only have to call the required method, for example, “this.sapProxy11.Rfc_Customer_Get(…)”;














SOAP Support Extensions
SAP connector for Microsoft .NET 2.0 supports Soap. SAP connector for Microsoft .NET 1.x also supported Soap, but with version 2.0 the use of Soap is easier. It is now fully transparent to a client whether RFC or Soap is used. The underlying idea is to extend the “Connection” and “Destination” model. With SAP connector for Microsoft .NET 2.0 as well as with SAP connector for Microsoft .NET 1.0, the SAPClient class (and thus all client proxies) have a “Connection” property. In SAP connector for Microsoft .NET 1.0, you had to assign a “SAPConnection” object that was the container for RFC connections. You were able to create such an object directly, for example “proxy.Connection = new SAPConnection(connString)” Or you were able to create an object indirectly with the SAPClient’s constructor or the “ConnectionString” property: “proxy.ConnectionString = “…”” or “SAPProxy1 proxy = new SAPProxy(connStr);”
To build up a connection string, you could use a Destination or SAPLogonDestination object. In SAP connector for Microsoft .NET 2.0, this model has been extended: The SAPClient’s “Connection” property can contain either an object of class “RfcConnection” (which is the successor of SAPConnection) or an object of class “SoapConnection”. The new “SoapConnection” class builds the correct URLs and credentials as expected by the Soap entry of SAP Web Application Server 6.20. A static function “SAP.Connector.Connection.GetConnection() is available that creates the correct “Connection” class for the connection string.
The following sets a SoapConnection to the proxy: “proxy.Connection = Connection.GetConnection(“http://appserver:1080/sap/bc/soap/rfc”) Compare this with the following, which sets an RFC connection: “proxy.Connection = Connection.GetConnection(“ASHOST=iwdf9401 SYSNR=1 CLIENT=801 USER=hille PASSWD=***** LANG=de). On the other hand, “Destination” and “SAPLogonDestination” have been extended to create URL connection strings instead of RFC connection strings. Therefore the connection classes have many new properties; of which the most important one is “UseSoap”. When it is set to “False” (default), the “Destination” classes work as before. When it is set to “True”, it produces an URL instead. Destination destination1 = new Destination(); … // set properties here destination1.UseSoap = false; proxy.Connection = Connection.GetConnection(destination1); // running with RFC destination1.UseSoap = true; proxy.Connection = Connection.GetConnection(destination1); // running with Soap. Connection.GetConnection exists in several overloads to support different kinds of connection and connection providers, automatic connection pooling, and so on.

Benefits
i) SAP integration with Visual Studio .NET supports development of more-secure applications and controls.
ii) The SAP .NET Connector 2.0 connects .NET applications with business processes running in SAP systems, including ERP (R/3), CRM, and BW. The connector exposes the entire SAP business API through either SAP’s binary transport protocol (RFC) or via Web Services.
iii) BAPI specific exception handling like automatic retry and functional exception handling based on BAPI return values.
iv) “Smart dataset feature” of the new proxies. Proxies can be customized to contain any number of properties. These can be data-bound to controls. This makes the use of proxies even easier.

Conclusion
The ability to manage the flow of information – by connecting applications, people, and data – increases an organization’s operational efficiency, improves productivity, and reduces costs. Connecting people to data and to one another enables faster, more informed decisions and more highly empowered employees; and makes the most of a company’s human capital and information assets. By integrating line-of-business and .Net applications that are already in place, organizations increase the value of their investment in these systems and avoid the cost of replacing software.
The integration components of the .NET framework allow companies to access and share legacy SAP information throughout the enterprise and with partners. Companies can leverage Microsoft’s built-in Web Services to bring enterprise information to the desktop. Organizations can reduce manual processes by leveraging the XML capabilities of .Net. By creating processes that connect structured and unstructured data, this integration between Microsoft and SAP brings organizations tremendous business value.







5 comments:

Patrioteer said...

I know this post is a little old, but we are currently using the old 1.0 connector and are considering an upgrade to 2.0. We already have an extensive Bapi Library going and inuse by several production apps. So the queswtions are: 1) Can we have both versions installed and in use at the same time? and 2) What are the benefits to going to 2.0?

Thanks.
Rog.

justicet said...
This comment has been removed by the author.
justicet said...

Hi! please assist. I have just installed the .Net SAP Connector 3.0 , nut 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!!!

Cindy Dy said...


Thank you for the information. You have a very good article. I found it informative and useful. Keep up the good work and God bless!

www.gofastek.com

ERP said...

ERPTREE is a leading oracle fuison HCM Training Institute. we offer this course through online we have great experience in succeeding students through online courses. we can calculate our performance through their honest comments in our sites in supporting our services. we have referral program so candidates can earn money through referral. you can share your live experience with other can generate you some money.


Oracle fusion HCM Online Training

Oracle Fusion HCM Training

Search