Skip to Content
Author's profile photo Philip Johnston

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.

Step 1

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:

/wp-content/uploads/2013/03/pic__193206.jpg

Step 2

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:

/wp-content/uploads/2013/03/pic__193206.jpg

A Create Web Service Wizard will walk you through the steps.  Here is mine:

/wp-content/uploads/2013/03/p_193211.jpg

/wp-content/uploads/2013/03/p_193211.jpg

/wp-content/uploads/2013/03/p_193211.jpg

/wp-content/uploads/2013/03/p_193211.jpg

/wp-content/uploads/2013/03/p_193211.jpg

Once you finish this wizard, save and activate your web service.

Step 3

Go to transaction: SOAMANAGER

Choose the “Web Service Configuration” option from the Service Administration tab.

/wp-content/uploads/2013/03/pic__193206.jpg

You can now search for your service definition and select “Apply Selection” as follows:

/wp-content/uploads/2013/03/pic__193206.jpg

Choose the “Configurations” tab and select “Create”.  Enter details similar to the following and select “Apply Settings”:

/wp-content/uploads/2013/03/p_193211.jpg

Enter the following information on the “Provider Security” tab:

/wp-content/uploads/2013/03/p_193211.jpg

Save these changes.

Select (in the overview section):

/wp-content/uploads/2013/03/pic__193206.jpg

Copy the WSDL URL link that is provided.  You will need this for your .Net application

Step 4

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:

/wp-content/uploads/2013/03/p_193211.jpg

Now to test this Web Service, create a web form and enter code similar to the following:

/wp-content/uploads/2013/03/p_193211.jpg

When I execute this program, I see the following returned data:

/wp-content/uploads/2013/03/p_193211.jpg

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.

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.