Create an SAP Web Service, Call Web Service from .Net Application, Passing User Credentials
This example shows you how to create an SAP Web Service from a function module. The Web Service is then called from a .Net Application and passes the user credentials to execute the web service. This sample extends the prior example (http://scn.sap.com/docs/DOC-38764) which uses a default service account.
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:
A 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 used the username and password to authenticate against SAP for calling the web service. Now remember, this method does use HTTPBasic (clear text) and you would probably be better served using a more secure protocol such as SSL.