Consming SAP Web Services and .NET


The scope of this document is to describe integration of SAP Web Services and Microsoft .NET using Microsoft Visual Studio.

SAP WEB SERVICES AND VISUAL STUDIO .NET ARCHITECTURE AND OVERVIEW

BACK GROUND

SAP and Microsoft .NET can be integrated via couple of options. On the top: SAP Web Services can be consumed in a straight line in .NET web client, ASP.NET. ASP.NET has built in support for the consuming Web Service WSDL and generating the proxy code. Once we have the proxy code, that can be consumed in any .NET client applications like console application, web application, WCF application. 

1.gif

USING VISUAL STUDIO.NET TO GENERATE PROXY FROM SAP WEB SERVICE

There two steps involved the creation of the proxy. First create a wsdl for the given web service and then generate the proxy by consuming the WSDL. I will let you the reason behind it.

A. Creating WSDL from the Web Service URL.
  1. Open the Internet explorer and input the web service URL that is created in SAP server and click enter. Enter the credentials when it asks for. And click on OK button

    2.gif

  2. It will generate the WSDL for the web service

    3.gif

  3. Save the WSDL file to the disk with the WSDL extension and open the WSDL in .NET IDE or in the notepad.

    Find the 'System' in the WSDL and replace with "SYSTEM" because the namespace System is already reserved in Visual Studio. If you do not change the name of this element here to all capital letters, you will get errors when building the application.

    The next change you need to make on the WSDL is to rename all instances of "parameters" to "parameter." This is necessary to be able to read the methods of the Web service correctly in Visual Studio. Save the changes for further use to generate the proxy. 

    4.gif
B. In the second step, Follow the steps to generate the proxy for client.
  1. Open up the Microsoft Visual Studio any version. Create a blank solution with the same if SAPDotNetIntegration.

  2. Create a new class library project, by adding a new project to the solution. Name it is SAPWebServiceProxyLibrary.  The purpose of creating it as separate library is the it can be reference in .net client application for use.

  3. Right click oin the SAPWebServiceProxyLibrary project and click on 'Add web referance' context menu.

  4. Enter the Disk path of the WSDL generated in the first step in the URL drop down and click on 'Go' button. 

    5.gif

  5. System shows the following screen.

    6.gif

  6. Click on the 'Allow block content' as shown below. Which show the generated WSDL.

    7.gif

    8.gif

  7. Enter 'SAPWebServiceNamespace' in the 'Web reference name' text box and click on 'Add Referance' button. Which will generate the .NET proxy class of the client to consume. 

  8. Compile the solution. Now the proxy class is ready to be consumed by .NET clients. Which will be detailed in the next section.

  9. Also following entries are made to the app.config for runtime use to identify the web service.

    9.gif
CONSUMING PROXY IN .NET CLIENT

Follow the steps to create and read the data by using the proxy. 
  1. Add a new 'ASP.NET Web application' to the SAPDotNetIntegration solution. And name it as AspDotNetClient.

  2. Add the reference to the SAPWebServiceProxyLibrary.dll compiled and saved on the disk. By right clicking on the AspDotNetClient, and clicking on the 'Add reference context' menu.

  3. Add the following statement to the code behind

    using
    SAPWebServiceProxyLibrary.CustomerMasterNamespace;

  4. Following are the basic lines of code to be written to asscess the data from SAP system.

    //Creating the Service
    ZSN_WEBSERVICEService
    _proxy = new ZSN_WEBSERVICEService();
    //stores the return row XML data from the SAP web service

    String
    outData;

    //Setting the User Credentials
    _proxy.Credentials = new NetworkCredential("loginName", "password");
    //We have a stateful communication therefore we have to use a //CookieContainer
    CookieContainer _cookie = new CookieContainer();
    _proxy.CookieContainer = _cookie;
    // p_filepath_app is the input parameter to identify the specific SAP web // service
    outData = _proxy.ZsnWebservice("xmlfilepathonthesapserver");


Similar Articles