ARTICLE

Consming SAP Web Services and .NET

Posted by Srihari Chinna Articles | Web Services in C# August 18, 2010
The scope of this document is to describe integration of SAP Web Services and Microsoft .NET using Microsoft Visual Studio.
Reader Level:

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");

Login to add your contents and source code to this article
post comment
     

Hi nice blog. I am trying to consume sap web service using asp.net. I have done all the steps which you have mentioned. But i couldn't figure out the xml file path to be pass as a argument to the _proxy.ZsnWebservice(). Where can I find this?

Posted by Saravanan Ramamurthy Mar 26, 2013

Hi We are trying to connect to a SAP web service from an smart device using .NET Compact Framework. Is it possible? If yes, what is needed? Thanks

Posted by Pablo Oct 05, 2011

Hi,

SAP developers will better knwo about the SAP versions supported. for me following are the steps to create a webservice.

Activate change pointers for message type: ex: DEBMASAfter activation of change pointer in the <<Table1>> . whenever changes happens to the table the IDoc will  trigger with all the changed data and create a xml file.Create Function module, ex:, ZSN_WEBSERVICE with RFC Enable function module. Write the all necessary code to get all related data into one XML output string.


I am going to post another artical on consuming .NET web service in SAP that will clear many details of SAP.

Thanks,
Chinna

Posted by Srihari Chinna Aug 24, 2010

Srihari, I am developing an application that integrates SAP and .net and have some doubts.

I'm .net developer. All SAP versions support Web service? What sap developers need to make a web service?

Thanks

Posted by nathan guedini Aug 23, 2010

thanks, Mahesh.

Posted by Srihari Chinna Aug 21, 2010
COMMENT USING
PREMIUM SPONSORS
Over-C is a holistic consortium of communications and technology specialists. We build, deploy and market both business as well as consumer products and solutions.
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Get Career Advice from Experts