July 15, 2013

Creating a Web Service Consumer


Here I will be showing how to create a Web Service Consumer in SAP. We are going to consume a Web Service which I have created earlier. You can use this link to access it.

Step 01: 
Create a Consumer Proxy.

Go to transaction SE80 and then open the package you are working on. You may also select the Local Objects if you are not going to use a package. I'm going to save this as a Local Object for this tutorial. Navigate to Enterprise Services->Service Consumer, right click and select "Create".




The "Create Service Consumer" wizard should pop up. Here you have to provide a source for the Web Service definition (WSDL source). For this example we're going to select the option external WSDL and click Continue.



Next the wizard asks for the source location. We're going to select the option URL and provide the WSDL URL of the previous Web Service provider which I have created here. The WSDL URL should be the URL that you get when you view the WSDL in the browser using "Open WSDL document for selected binding or service".


Next, select the package you are going to save the object to. For this example I'm going to save it as a local object and click Continue.


Next is a final wizard screen and here you just have to click Continue.


Once you click Continue, You will be asked for login information. This will depend on the system you are accessing the WSDL from. Since we're using the previously created Web Service from SAP it will ask for the login details to SAP Application Server.


After you have provided all the necessary information the inactive service consumer is displayed to the right of the screen. For this example you don't have to do anything here, just save and activate the service consumer proxy.




Step 02:
SOA manager configuration.

run the transaction SOAMANAGER. Select the "Web Service Configuration" link. Select "Consumer Proxy" from the "Search By" drop down and enter the Service Consumer Proxy name you created and press "Apply Selection".


Select the "Configurations" tab and click "Create". This will open a window to enter the logical port name and some other configurations. Enter a name for the Logical Port and a description. Select the option WSDL configuration because we're providing a URL for the WSDL. Also provide the Username and password for the WSDL URL and click "Apply Settings".


Another screen should pop up showing some details of the WSDL you are accessing.Press "Apply Settings".


Then you will have to provide some more information for the configuration of the logical port such as Username and Password. This may vary according to the security settings you provided when you were creating the service consumer. Press "Save".



Step 03:
Write a program to call the consumer proxy to consume the web service.

Write a program similar to the following which can be used to consume the web service.











July 12, 2013

Creating a Web Service Provider in SAP


This tutorial takes you through the steps involved in successfully creating a Web Service in SAP. I will be testing this Web Service (Consuming the Web Service) using a standalone application which is built on Java called SoapUI. You can download this application at www.soapui.org.


Step 01:
Create the function module (I have created a function module named as ZWEBSERV_01) which you will be using to publish as a Web Service. I have created a simple function module which will import a company code and it will give out details of the company code. Also if I do not provide a specific company code it will return a list of company codes as tabular data. The interface of the function module is as follows:





 


Step 02:
Create a Service Definition for the function module. From the function builder navigate to Utilities->More Utilities->Create Web Service->From the Function Module menu. This will open up a wizard.



Give a Service Definition Name and a Description and click continue.


There is nothing to do here. Just an option for to map the function module name. Click continue.


Select a security profile for the Service Definition. I selected "Authentication with User and Password, No Transport Guarantee". Click continue.


Select the package for the object. I selected it as a local object. Click continue.


Click "Complete" at the last screen of the wizard.


Then the screen will go to the Change Service Definition screen. There are a few setting that you can change here but for this example I'm not going to change anything. Save and activate the Service Definition.



Step 03:
Do the configuration for the Service Definition in the SOAMANAGER. Run transaction SOAMANAGER and it will open the web browser and direct you to the SOA Management console. Make sure you are open this in the right client because the configurations here are client specific.







Click the "Web Service Configuration" link and enter the previously created Service Definition in the "Search Pattern" field, Select "Service Definition" from the "Search By" drop down list and click "Go". This should display the Service Definition you created in the "Search Results" list.


Select the Service Definition line and click "Apply Selection". This will open up the "Details of Service Definition" below. The "Configuration Status" should display 0 for "Services" and "Bindings".




Click the "Configurations" tab and click "Create" to create a binding for the Service Definition. Enter the "Service Name", "Description" and "New Binding Name" and click "Apply Settings". This will create a binding for the Service Definition which is used to expose the Web Service. I'm entering the same name for the all of the fields.




The configuration for the binding will open below. Select the options as in the following diagram and click "Save".

Now you have exposed the Web Service so that a consumer can access it. Click the "Open WSDL document for selected binding or service". This will open up the browser with the WSDL displayed with the binding for your Service Definition. Use that URL as the WSDL for the Web Service Consumer.





Testing/Consuming the Web Service

Step 01:
Open the SoapUI program and create a new SoapUI project. Enter the previous WSDL url in the "Initial WSDL/WADL" field.Check the create requests check box and click OK. You will probably will be asked for the login details to SAP.


The added project will be displayed to the left side and you can double click the request to open up a window which displays the request and a response. The request is the SOAP payload. Enter a company code between the <IM_BUKRS></IM_BUKRS> tag and click the submit request button. This should give the response in the window to the left.