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
Using Visual Studio.NET 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.
- 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
- It will generate the WSDL for the web service
- 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
B. In the second step, Follow the steps to generate the proxy for client.
- Open up the Microsoft Visual Studio any version. Create a blank solution with the same if SAPDotNetIntegration.
- 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.
- Right click oin the SAPWebServiceProxyLibrary project and click on 'Add web referance' context menu.
- Enter the Disk path of the WSDL generated in the first step in the URL drop down and click on 'Go' button.
- System shows the following screen.
- Click on the 'Allow block content' as shown below. Which show the generated WSDL.
- 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.
- Compile the solution. Now the proxy class is ready to be consumed by .NET clients. Which will be detailed in the next section.
- Also following entries are made to the app.config for runtime use to identify the web service.
Consuming Proxy in .NET Client
Follow the steps to create and read the data by using the proxy.
- Add a new 'ASP.NET Web application' to the SAPDotNetIntegration solution. And name it as AspDotNetClient.
- 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.
- Add the following statement to the code behind
- Following are the basic lines of code to be written to asscess the data from SAP system.
//Creating the ServiceZSN_WEBSERVICEService
_proxy = new ZSN_WEBSERVICEService();
//stores the return row XML data from the SAP web serviceString outData;
//Setting the User Credentials_proxy.Credentials = new NetworkCredential("loginName", "password");
//We have a stateful communication therefore we have to use a //CookieContainerCookieContainer _cookie = new CookieContainer();
_proxy.CookieContainer = _cookie;
// p_filepath_app is the input parameter to identify the specific SAP web // serviceoutData = _proxy.ZsnWebservice("xmlfilepathonthesapserver");
That's all. happy coding.