Create an SAP Web Service, Call Web Service from .Net Application, Using Service Account
This example shows you how to create an SAP Web Service from an SAP function module for use by a service account. The Web Service is then called from a .Net Application.
In reality, you might not want Web Services to be used by service accounts since anyone who knows the WSDL would be able to execute the Web Service. I’ll show you how to actually pass the user credentials to the web service in my next example.
Either create or choose an SAP function module you want to enable as a web service. Make sure it is RFC enabled. This is what I will use for this example:
Now we need to create a web service from the RFC definition. SAP has provided a very nice option of creating the proxy stub for you. From the utilities menu, choose the following:
The Create Web Service Wizard will walk you through the steps. Here is mine:
Once you finish this wizard, save and activate your web service.
Go to transaction: SOAMANAGER
Choose the “Web Service Configuration” option from the Service Administration tab.
You can now search for your service definition and select “Apply Selection” as follows:
Choose the “Configurations” tab and select “Create”. Enter details similar to the following and select “Apply Settings”:
Enter the following information on the “Provider Security” tab:
Save these changes.
Select (in the overview section):
Copy the WSDL URL link that is provided. You will need this for your .Net application
Now you are ready to call this web service from a .Net (or other) application.
Open up your Visual Studio project and add a web reference to the WSDL URL you copied above.
Here is my web reference:
Now to test this Web Service, create a web form and enter code similar to the following:
When I execute this program, I see the following returned data:
As you can see, we successfully executed the SAP web service from the .Net application. This example is using the same service account for every call. A more realistic example would be to use the credentials of the user of the web page. See my other example for that.