1
Whoa, I took a look at Stack behind a simple question, but it’s getting me confused. Knowing the concept of Webservice is relatively easy, but practice is the focus of this issue. I saw some other questions here, but they were not answered because of how the question was asked, so I want to specify, exemplify the best possible so that they can help me.
It is easy to find Libs to develop a Webservice, the question is, conceptually can I create a Webservice without any Lib? For example, receive the data via Post, or Get, manipulate it and return a Json response, or XML to an application developed on a different platform? Maintaining interoperability and other features of a web service...
How Gambiarra ever did that:
<?php
include 'servidor.php';
$resposta=array();
if(isset($_GET['comando'])){
$comando=$_GET['comando'];
switch($comando){
case "Inserir":
if(isset($_GET['nome']) && isset($_GET['ra'])){
$r=inserirContato($_GET['nome'] , $_GET['ra']);
if($r){
$resposta['codigo']=1;
$resposta['mensagem']="Sucesso ao inserir!";
}else{
$resposta['codigo']=0;
$resposta['mensagem']="Erro ao inserir!";
}
}else{
$resposta['codigo']=0;
$resposta['mensagem']="Campos ausentes!";
}
break;
But I’ve done that too:
<?php
include 'conexao.class.php';
include 'lib/nusoap.php'; // BAIXADO DA INTERNET
$server = new nusoap_server;
$server->configureWSDL('agenda','urn:agenda');
$server->wsdl->schemaTargetNamespace='urn:agenda';
$server->wsdl->addComplexType(
'Contato',
'complexType',
'struct',
'all',
'',
array(
'id'=>array('name'=>'id','type'=>'xsd:int'),
'nome'=>array('name'=>'nome','type'=>'xsd:string'),
'telefone'=>
array('name'=>'telefone','type'=>'xsd:string')
)
);
$server->wsdl->addComplexType(
'ArrayString',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(
array('ref'=>'SOAP-ENC:arrayType',
'wsdl:arrayType'=>'xsd:string[]')
),
'xsd:string'
);
$server->register(
'procurarContato',
array('id'=>'xsd:int'),
array('return'=>'tns:Contato'),
'urn:agenda',
'urn:agenda#procurarContato',
'rpc',
'encoded',
'Procurar contato'
);
function procurarContato($id){
$con = new conexao();
if($con->connect()){
$query=mysql_query("SELECT * FROM contato where id='$id'");
$row = mysql_fetch_array($query);
$contatos=array(
'id'=>$row['id'],
'nome'=>$row['nome'],
'telefone'=>$row['telefone']
);
$con->disconnect();
return $contatos;
}else return null;
}
Regarding the delivery of the desired information both worked, although one I used a lib to have a documentation and be something more formal and the other not. It may seem that my question is the answer of itself, but there is my doubt, these two forms above are Webservices? If not, how would you classify the first form? I can improve the question if it seems too broad or vague. (Remembering that the snippets of the codes pasted here are only to illustrate the use of the library, there are still the functions, the parses for the repeats etc.
conceitualmente posso criar um Webservice sem nenhuma Lib?
Conceptually, Libs are "standard" webservices, created with no lib, so you don’t have to create your own :)– Ricardo Moraleida
Ricardo ball show, thank you very much!
– Rafael Rezende