Algunos de nosotros ya estamos sufriendo este cambio en el mundo empresarial. La tecnología SOA se esta empezando a implantar con fuerza dentro de SAP; y debemos estar preparados.
En este blog quiero mostrar la forma de consumir un Servicio Web externo a SAP desde un report / función, sin utilizar XI/PI. Debemos tener en cuenta, que para poder realizar esta práctica, debemos tener en nuestro sistema WAS >6.10
El procedimiento es el siguiente:
Entramos en la web http://www.webserviceX.NET, donde hay disponibles algunos servicios para que podamos probar.

Pulsamos sobre
. A continuación accedemos a 
. Buscamos la categoría de servicios 
.

Pulsamos sobre



Nos muestra los servicios disponibles dentro de esa categoría:

Introducimos “Spain” y pulsamos sobre

Nos aparecerá una pantalla mostrándonos un mensaje XML con los resultados:
Muy bien, ahora nosotros vamos a programar muestro cliente para consumir ese Web Service.
Los datos que necesitamos serán los siguientes:
- WSDL, donde se indica la estructura del servicio y todos los datos relevantes
- Location, localización del servicio
- SOAPAction, acción que debe realizar el servicio
Localizamos esos datos en el WSDL:


que indica la operación.
Una vez recopilados todos estos datos, procedemos a nuestra programación, desde
*--- Declaracion
DATA: rlength TYPE i,
txlen TYPE string ,
http_client TYPE REF TO if_http_client,
wf_string TYPE string ,
wf_string1 TYPE string .
pais = 'Spain'.
*----Creamos el Soap Envelope
CLEAR wf_string.
CONCATENATE
'<?xml version="1.0" encoding="utf-8"?>'
'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.
xmlsoap.org/soap/envelope/">'
'<soap:Body>'
'<GetAirportInformationByCountry xmlns="http://www.webserviceX.NET">'
'<country>' pais '</country>'
'</GetAirportInformationByCountry>'
'</soap:Body>'
'</soap:Envelope>'
INTO wf_string.
CLEAR :rlength , txlen .
rlength = STRLEN( wf_string ) .
MOVE: rlength TO txlen.
CLEAR: wf_proxy, wf_port .
CALL METHOD cl_http_client=>create_by_url
EXPORTING
url = 'http://www.webservicex.net'
proxy_service = '8080'
IMPORTING
client = http_client.
CALL METHOD http_client->request->set_header_field
EXPORTING
name = '~request_method'
value = 'POST'.
CALL METHOD http_client->request->set_header_field
EXPORTING
name = '~server_protocol'
value = 'HTTP/1.1'.
CALL METHOD http_client->request->set_header_field
EXPORTING
name = '~request_uri'
value = '/airport.asmx'.
CALL METHOD http_client->request->set_header_field
EXPORTING
name = 'Content-Type'
value = 'text/xml; charset=utf-8'.
CALL METHOD http_client->request->set_header_field
EXPORTING
name = 'Content-Length'
value = txlen.
CALL METHOD http_client->request->set_header_field
EXPORTING
name = 'SOAPAction'
value = 'http://www.webserviceX.NET/GetAirportInformationByCountry'.
CALL METHOD http_client->request->set_cdata
EXPORTING
data = wf_string
offset = 0
length = rlength.
CALL METHOD http_client->send
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2.
CALL METHOD http_client->receive
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3.
CLEAR wf_string1 .
wf_string1 = http_client->response->get_cdata( ).
WRITE:/ wf_string1.