0% encontró este documento útil (0 votos)
99 vistas

Webservice Tutorial

1) El documento describe los pasos para crear un webservice en SAP, incluyendo crear una función de acceso remoto, configurar el servicio web, publicarlo y probarlo. 2) También explica cómo crear un cliente PHP para consumir el servicio SAP mediante SOAP y cómo crear un servicio web PHP para ser consumido desde ABAP. 3) Los pasos clave son crear una función ABAP, generar el servicio web, obtener la descripción WSDL, e implementar un cliente SOAP en PHP o ABAP.

Cargado por

o
Derechos de autor
© © All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como DOC, PDF, TXT o lee en línea desde Scribd
0% encontró este documento útil (0 votos)
99 vistas

Webservice Tutorial

1) El documento describe los pasos para crear un webservice en SAP, incluyendo crear una función de acceso remoto, configurar el servicio web, publicarlo y probarlo. 2) También explica cómo crear un cliente PHP para consumir el servicio SAP mediante SOAP y cómo crear un servicio web PHP para ser consumido desde ABAP. 3) Los pasos clave son crear una función ABAP, generar el servicio web, obtener la descripción WSDL, e implementar un cliente SOAP en PHP o ABAP.

Cargado por

o
Derechos de autor
© © All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como DOC, PDF, TXT o lee en línea desde Scribd
Está en la página 1/ 14

Pasos para la construcción de un Webservice en S.A.

Prerrequisitos.

Se debe crear un paquete y en él guardar todo lo correspondiente al Webservice.

Lo primero que debemos crear es una función de acceso remoto de tipo RFC y construir
nuestra lógica, lógica que será consumida mediante el Webservice.

Una vez terminemos este proceso, damos click derecho sobre la función y
seleccionamos Crear-> Servicio Web
Después nos aparecerá un Wizard que nos ayudara con la configuración del servicio
Web.

Introducimos el nombre del servicio Web y una Descripción breve.


El punto final será por default mi función.

Asignamos un perfil para seguridad, y no seleccionamos la casilla de verificación.


Cuando terminemos tendremos en nuestro paquete una nueva carpeta con el nombre del
servicio que creamos, pero aun no lo hemos liberado, es decir el servicio Web no esta
activo.

Para ellos vamos a la transacción WSCONFIG en ella seleccionamos nuestro servicio y


una variante, damos click en crear. Ojo necesitamos cierto perfil basis para configurar
esta parte, si no nos deja entramos a la su53 y miramos que objeto nos falta.

Dentro de esta pantalla damos click en Det.ICF

Ahora damos click en el último del árbol de jerarquía, y allí configuramos los datos de
login para el servicio Web, es posible dar estos datos dinámicamente pero en nuestro
caso asignaremos el usuario para evitar el proceso de autenticación.

-
 Datos de autenticación, damos clic en guardar y volvemos a la pantalla anterior

Verificamos que nuestro servicio Web este activo en estado verde.


Ahora vamos a la transacción WSADMIN y en ella encontraremos nuestro servicio web
publicado .
Para probar que nuestro web service esta bien seleccionamos el servicio y damos click
en el siguiente icono.
Se nos abrirá el navegador web con una pagina como la sgte

Ya esta lista para consumir el servicio web, ahora para probarlo y hacerle test, se
recomienda crear un programa ABAP pero antes hay que crear un Proxy veamos como.

Ahí damos click en URL/ destino HTTP

Acá nos pide nuestra URL, es el URL que usamos cuando vimos la página en nuestro
navegador, mi caso:
http://sapdes.jddominio.com:8010/sap/bc/srt/rfc/sap/ZIN_RADICACION_VI?sap-
client=100&wsdl=1.1

Después nos pide un paquete y un prefijo, damos el paquete donde esta toda nuestra
lógica. Una vez creado el Proxy vamos a la transacción LPCONFIG, en ella
configuramos el puerto. Damos clic en crear y ya tenemos todo listo ahora scon la sgte
explicación montamos el programa.
Integrating PHP and ABAP Using Webservices

Purpose
One of the paradigms of modern architecture is service orientation (SOA) with it's SAP flavour ESA (enterprise
service architecture). An important principle of SOA is implementation transparency, i.e. it doesn't matter in
which language a service is being implemented. This allows to combine services from different specialised
environments into composite applications or processes.

PHP is a scripting language with an always growing userbase having its strenghts in a number of areas, in which
it can complement ABAP well (e.g. xml schema validation, small footprint graphics manipulation, cryptology, ...)
Integrating PHP and ABAP therefore adds a valuable opportunity for those creating state-of-the-art solutions
around the Netweaver platform.

In this weblog I'll give a simple tutorial to show how to make use of webservices technologies to integrate PHP
and ABAP. In my opinion the features of webservices and SOAP make the use of the good old PHPRFC library -
which did such a good job for many years, obsolet. One interface technology less.

Prerequisites
The examples shown here require ABAP WAS 6.40+ and PHP 5.x. The soap libraries in PHP are not enabled by
default, so we have to enable them by adding
extension=php_soap.dll
to the php.ini file. For development we don't want the WSDLs to be cached once downloaded so we have to set
soap.wsdl_cache_enabled=0
in php.ini.

Calling an ABAP webservice from PHP


First we have to create the webservice in ABAP. We create a very simple webservice, accepting one input
parameter and returning a parameter based on it. So, we create a function module ZTW_WS1:
FUNCTION ZTW_FUB1.
*"--------------------------------------------------------------------
--
*"*"Lokale Schnittstelle:
*" IMPORTING
*" VALUE(P_IN) TYPE STRING
*" EXPORTING
*" VALUE(P_OUT) TYPE STRING
*"--------------------------------------------------------------------
--

concatenate 'ABAP says: Hello' space p_in into p_out separated by


space.
concatenate p_out '!' into p_out.

ENDFUNCTION.
This is probably the most simple function module to test the functionality. It expects a name, say Sue, and
returns ABAP says: Hello Sue! We remote-enable, save and activate it. Next we create a webservice based on it.
Since this is a bit different for different versions of ABAP WAS, please consult the documentation for it.
Regardles of the version it's quiet simple, just right-click the function module and find the appropriate action or
create a new object of type webservice interface. Do not forget to release the service for the soap runtime.
When everything is set up, we get the WSDL (webservice description language; 'the service description') at the
following address:
http://tonysub:8000/sap/bc/srt/rfc/sap/ZTW_WS1?sap-client=100&wsdl=1.1
where tonysub is the name of our ABAP host. Just view it in your browser if you have never seen one :-) The
next thing is to create a client in PHP to consume this service. SOAP support is built-in for PHP 5.x so we can
immediately start to code our client:
<?
$wsdlurl ="http://tonysub:8000/sap/bc/srt/rfc/sap/ZTW_WS1?sap-
client=100&wsdl=1.1";
$login = "bcuser";
$password = "minisap";
?>

<HTML><HEAD><TITLE>soap 1</TITLE></HEAD>
<BODY>

<? if(!isset($name)) { ?>


<form action="soap1.php" method="post">
Your name: <input type="text" name="name">
<br>Debug? : <input type="checkbox" name="debug"
value="true">
<br><input type="submit" value="Go!">
</form>

<? } else {
$client = new SoapClient($wsdlurl,
array('login' => $login,
'password' => $password,
'trace' => true,
'exceptions' => true));

try {
echo $client->ZtwFub1(array('PIn' => $name))->POut;
}
catch (SoapFault $e) {
echo 'Caught an Error: [' . $e->faultcode . '] - ' . $e-
>faultstring;
}

if(isset($debug)) {
echo "<hr><pre>\n";
echo "Request :\n".htmlspecialchars($client-
>__getLastRequest()) ."\n";
echo "Response:\n".htmlspecialchars($client-
>__getLastResponse())."\n";
echo "</pre>";
}
}
?>
</BODY></HTML>
There's 'a lot' of coding masking the simplicity of the webservice call, so here's the crucial parts again:
The constructor:
$client = new SoapClient($wsdlurl,
array('login' => $login,
'password' => $password,
'trace' => true,
'exceptions' => true));
And the actual service call(and display of the result):
echo $client->ZtwFub1(array('PIn' => $name))->POut;
The rest of the coding shows
 an HTML form letting you enter your name and decide if you want to see debugging information

 SOAP error handling


 debugging of the SOAP communication

Calling a PHP webservice from ABAP

First we create a webservice in PHP. This is not so easy as one might expect from PHP.
The reason for this is that using the standard SOAP functions you need a WSDL first to
instanciate a webservice. There are libraries on the internet allowing to autogenerate a
WSDL based on some PHP functions but those libraries are not too elaborate yet. One
good solution is the one provided by nusoap. Unfortunately this library collides with the
standard libraries since they use the same names for SOAP classes. So we create the
WSDL ourselves. We already have one template which makes this tutorial nicely
symmetrical. We use the one created for the ABAP webservice and adopt it for our
needs.
<?xml version="1.0" encoding="utf-8" ?>
<wsdl:definitions targetNamespace="urn:tonysub/soapexample1"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="urn:tonysub/soapexample1"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:types>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns="urn:tonysub/soapexample1"
targetNamespace="urn:tonysub/soapexample1"
elementFormDefault="unqualified"
attributeFormDefault="qualified">
<xsd:element name="ZtwFub1">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="PIn" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="ZtwFub1Response">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="POut" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>
<wsdl:message name="ZtwFub1">
<wsdl:part name="parameters" element="tns:ZtwFub1" />
</wsdl:message>
<wsdl:message name="ZtwFub1Response">
<wsdl:part name="parameters" element="tns:ZtwFub1Response" />
</wsdl:message>
<wsdl:portType name="ZTW_WSX">
<wsdl:operation name="ZtwFub1">
<wsdl:input message="tns:ZtwFub1" />
<wsdl:output message="tns:ZtwFub1Response" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="ZTW_WS1SoapBinding" type="tns:ZTW_WSX">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="ZtwFub1">
<soap:operation soapAction="" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="ZTW_WS1Service">
<wsdl:port name="ZTW_WS1SoapBinding"
binding="tns:ZTW_WS1SoapBinding">
<soap:address
location="http://tonysub/ws/soapserver1.php" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
Mainly we adopt some namespaces to point to our own namespace
urn:tonysub/soapexample1 and the SOAP:address location to point at our webservice at
http://tonysub/ws/soapserver1.php. We save this as soapserver1.wsdl to our
webdirectory. Havin the WSDL it's very easy to create the webservice in PHP
<?

function ZtwFub1($name) {
return (array(POut => "PHP says: Hello " . $name->PIn . "!"));
}

$server = new SoapServer("soapserver1.wsdl");


$server->addFunction("ZtwFub1");
$server->handle();

?>
That's the PHP webservice. We could test it by simply pointing the client above to the
new WSDL location, i.e. http://tonysub/ws/soapserver1.wsdl (and clearing login an
password for this example). But we quickly move on to test it from the ABAP side. We
go to SE80 again and create a so called webservice proxy obbject using the same
WSDL. We follow the wizard and get a proxy object, e.g. ZTW_CO_ZTW_WSX.
DDIC structures for the input and and output parameters are created, here
ZTW_ZTW_FUB1 and ZTW_ZTW_FUB1. Finally we have to go to transaction
LPCONFIG and create a logical port for our proxy object. So, the only thing left to do is
write a report to make use of this proxy object.
*&--------------------------------------------------------------------
-*
*& Report ZTW_CALL_WS
*&
*&--------------------------------------------------------------------
-*
*&
*&
*&--------------------------------------------------------------------
-*

REPORT ZTW_CALL_WS.

data: my_client type ref to ztw_co_ztw_wsx,


my_result type ztw_ztw_fub1response,
my_input type ztw_ztw_fub1.

parameters: my_name(20) type c.

my_input-pin = my_name.

create object my_client.

call method my_client->ZTW_FUB1


exporting INPUT = my_input
importing OUTPUT = my_result.

write: / my_result-pout.
Voilá, we end up with the following: An input screen to enter a name

An the result showing the answer of the PHP webservice

Basically thats it. Everything else is fiddling around with more complex data structures
(nested structures in ABAP and nested arrays in PHP). And, of course, elaborating on
more useful examples :-)
Follow-up weblogs will cover such topics. Stay tuned.
Further documentation on the PHP SOAP libraries can be found here.

Anton Wenzelhuemer is a solution architect working on Netweaver solutions in the


healthcare industry


Here is what we've got so far. An input screen to input your name:

An the result showing the answer of the webservice

También podría gustarte