Monday, 15 April 2013

Create Web Services

Using SAP XI/PI middleware we can create and expose WebServices, in this blog we are going to try to explain how an ABAP WebService can be created, exposed and tested only using ABAP.

First, we have to expose a Function Group as an Enterprise Service which is going to be ready to be called.
We’ll use Function Group Z_WEBSERVICE_TEST which has Function ModuleZ_CALCULO and we are going to expose it as an Enterprise Service.
We are using the wizard for Web Service creation.
Right click on the Function Group, then select Create -> Web Service

Imagen1.png

Write the Service Definition Name, a brief description and set the EndPoint as Function Group

Imagen2.png

We have to specify the Function Group name that is going to implement this Service Definition.

Imagen3.png


Select the Function Module.
Imagen4.png

Use the default profile called PRF_DT_IF_SEC_LOW to establish the lowest security profile in this Service Definition.
Make sure to check the field “Deploy Service”. If you don’t check the field, you can complete this step later manually from transaction code SOAMANAGER using the option for creating an EndPoint in 'Configurations' tab.

Imagen5.png

Check “Local Object” field to save the object locally (not transport)

Imagen6.png

In the final step choose the “Complete” option

Imagen7.png

Now that we have completed the previous step we can see the next screen where we can explore the service definition.

Imagen8.png

We have to enter to the trx. SOAMANAGER and choose the tab Application and Scenario Communication -> Single Service Administration.

Imagen9.png

We have to search the WS Definition that we created.

Imagen10.png

When we click on “Open WSDL Document for selected binding” a new windows pops up with the WSDL document:

Imagen11.png

The final WSDL file in now available.

Imagen12.1.png


With this, we have finished the creation of the WebService and it's ready to be used for any external application.

Note: If you change some parameters in you function, you need to update it in the service definition. To do this go to trx. SE80 and select your previously created Service Definition and do a syntax check, then it will ask you if you want to correct the new parameters in the definition.

In the next chapter we are going to find how can we consume this WS using an ABAP proxy class.

In this part, we’ll see the process to create Proxy consumer service.
First, we have to start the wizard to create a new service using trx. SE80. Right click and thenCreate->Enterprise Service.

Imagen1.png

This time, in Object Type field we choose Service Consumer:

Imagen2.png

For the Service Consumer source, we can choose amongst Enterprise Service Repository, URL or the path of WSDL a local file, UDDI, and the Service Registry.
Please select URL/HTTP Destination.

Imagen3.png

Fill with the URL of the WSDL previously created.
Imagen4.png

Before continue, we enter to SOAMANAGER transaction code and choose: Application and Scenario Communication ->Single Service Administration.

Imagen5.png

Search the Service previously created and choose “Apply Selection”. Now we can see the Service Definition details.

Imagen6.png
Imagen7.png

You have to click on the “Open Web Service navigator for Selected Binding” link. The combo button shows the Endpoint defined for the Service. It’ll pop up the WSDL where we have to take the URL to create the proxy.

Imagen8.png
Use the URL in the wizard:
Imagen9.png

Fullfil the necesary data in the wizard.

Imagen10.png

In final step, you can click on “Complete” to start the creation of the Proxy object.

Imagen11.png
Enter your login data:

Imagen12.png

The proxy class is shown. Click on “Save and Activate”.

Imagen13.png

Go back to the SOAMANAGER trx. to configurate a logical port for our service provider.
Logical ports are made to configurate the time features of a WS execution. We can create a logical port from LPCONFIG (obsolete) or SOAMANAGER as we are showing next.
A consumer proxy never stores details about a server URL (which is system specific). These details have to be configured through logical ports and EndPoints.
For example: when we transport a proxy class from a Development system to QA system. The proxy class doesn’t contain any information about which server the WS has to be called, this is handled by a logical port-.
Go back to the SOAMANAGER trx. This time, when you search in “Web Service Administration” choose “Consumer Proxy”. Don’t forget to click on “Apply Selection”a after highlighting the proxy.

Imagen14.png

In the Configuration tab, select “Create Logical Port”.

Imagen15.png

In the pop-up shown, you have to fill several parameters. First, give a name for the logical port and set it as the default logical port.
Next we have to select “Config. Type” based on WSDL.

The application reads all the security parameters needed to call this service directly from WSDL definition.
Finally, we have to fill the WSDL URL for the called Web Services. Also, you have to give the system user name and password to access the WSDL

Imagen16.png

If the creation was success, the system will take us back to the Config. Screen, where we can continue with the logical port configuration. Once more, introduce the user name and password (they are going to be used as a credentials to call this service and to save the logical port).

Imagen17.png

Imagen18.png



The next and final section is: Testing a Service Consumer Proxy:

In this section we will see how to test a proxy. To do this we can press the icon highlighted in the picture below (or pressing F8):

Imagen1.png

In the “Test Service Consumer” window, we choose the Logical Port that we previously created from SOAMANAGER transaction code:

Imagen2.png

Change to the XML editor, and modify the default values. You can also skip this and execute the request.

Imagen3.png

The response must display the calculation in XML mode.

Imagen4.png

Now if we want to consume the WS using ABAP, we have to enter to trx. SE80 and create a new report:

Imagen5.png

Drag and drop the proxy class ZTESTCO_ZWS_CALCULO and you’ll get a template to consume it as shown below:

Imagen6.png

Modify the template to call the WS.

Imagen7.png

Note: setting the logical port in EXPORTING parameters it’s not mandatory because when we created it from SOAMANAGER trx. we checked the “Logical Port is default” option.
Now we can execute it:
Imagen8.png

This is just a dummy report, but it’s enough to understand the basis about how to consume a WS.  

No comments:

Post a Comment